Had great fun a couple of weekends ago at the Arduino Introduction to Physical Computing course run by the Omniversity at Madlab, Manchester.
I’m interested in putting together a prototype for a second screen which shows information from your mobile phone (communicated via bluetooth) for use when on the push bike. Kind of like Sony Live View, or ePebble.
I’ve been thinking about this for a long while now, extending on from a phone application I developed a couple of years ago which helps you navigate when riding a bicycle.
Note: I’m aiming to post more about the phone app (called GPSJake) as a post mortem. It was something I was quite proud of at the time and would still find useful (once I’ve found time to port the J2ME code so I can run it on my Nokia N8). It provides functionality I find useful that I don’t think the current sports tracker / recreational mapping apps (e.g. sports tracker, endomodo, view ranger) provide.
The gist is the app allows you to spatially a register a photo of an Ordnance Survey map (say a photo taken on your phone of a map that you *own*).
Once registered the app shows your current position and provides other navigation functionality. More in a subsequent post.
The motivation behind the second screen prototype is that phones in these times come with GPS, maps etc that are really useful on a bike ride. The problem is I don’t want to keep having to get the phone out of my pocket or strap it to my handlebars. The form factor is way to draggy when I’m out on the road bike 😉 and i’m scared of smashing the crap out of it when I’m coming down Jacobs Ladder on my mountain bike.
The idea of the second screen is that is a piece of essentially dumb but rugged (and small) hardware that just receives images from the phone and sends responses from buttons back to the phone.
A friend suggested I start to mess around with Arduino which allows for the rapid prototyping of electronic projects. There are bluetooth and screen shields available for Arduinuo and it looks like a good way to progress.
Coincidentally, shortly after this conversation, I found out there was the Arduino course happening at Madlab – I signed up.
The Arduino course was very informative, well run in really relaxed, comfortable classroom situation. The included food (and post course beers) were great too. A thoroughly enjoyable way to spend a Saturday – tinkering with electronics and software – would definately attend another MadLab event.
Every attendee on the course received an Arduino Uno, various LED’s/potentiometers/resistors etc and course materials on a USB stick.
As an introduction the course was perfect, allowing us to understand simple circuits and develop code to run on the Arduino. The code was developed in the Arduino IDE (wonder if other IDEs can be used? Arduino plugin for Eclipse?), compiled and then uploaded to the Ardunio via USB. We also developed code which executed on a PC that could communicate with the Arduino over USB. We used the Processing IDE for this.
Initially we put together circuits consisting of a simple LED and then uploaded code to make the LED flash. Using the Processing IDE we then developed code which ran on the PC and interacted with the Arduino over the USB by reading the serial output from the Arduino. Doing this allowed us to read the values of 2 potentiometers that were plugged into the Arduino’s breadboard and convert the values into sound thereby making a theramin.
Anyway, I got home and quickly knocked together an etch-o-sketch with pointless LED’s. Here it is! The Glynn-o-Sketch.
So what’s going on here. Well there are 2 potentiometers (knobs which vary resistance but I’m no electronics whizz) on the circuit board that are connected to analog inputs on the Arduino board. The code that was uploaded to the Ardunio reads the values of these potentiometers and does 2 things:
1. Sets the brightness of the LED’s by mapping the values of the potentiometers to values acceptable by the LED’s. The LED’s have resistors associated with them and these are connected to Pulse Width Modulation digital pins on the Arduino board.
2. Writes the values of the potentiometers as a string to the USB.
Here’s the circuit (I used Fritzing to produce this):
Here’s the Ardunio code (based on that provided in the course) – glynnosketch.ino:
/* Sends the values of 2 potentiometers to the computer via USB. */ //pin A0 is an analog input pin from the potentiometer int pPinA0 = A0; //pin A1 is an analog input pin from the potentiometer int pPinA1 = A1; int pValueA0 = 0; int pValueA1 = 0; //PWM outputs int pled3 = 3; int pled5 = 5; void setup() { pinMode(pled3, OUTPUT); pinMode(pled5, OUTPUT); //Initialize the serial communication Serial.begin(9600); } void loop() { //Read the potentiometers pValueA0 = analogRead(pPinA0); pValueA1 = analogRead(pPinA1); //Write the values to the LED's. analogWrite(pled3, map(pValueA0, 0, 1023, 128, 255)); analogWrite(pled5, map(pValueA1, 0, 1023, 128, 255)); //Print the value to the serial port Serial.println(String(pValueA0) + ' ' + String(pValueA1)); //Wait a few milliseconds to allow the system to stabilise delay(10); }
Here’s the Processing code – glynnosketch.pde:
/* Reads a string from the USB port (sent by glynnosketch.ino). String contains the values of 2 potentiometers. Map the values of potentiometers to screen coordinates and draw a point at the screen coordinate. */ import processing.serial.*; // The serial port Serial myPort; void setup() { //Set the window size: size(400, 400); //List all the available serial ports println(Serial.list()); //Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); //Don't generate a serialEvent() until newline character: myPort.bufferUntil('\n'); //Set inital background: background(0); } void draw () { //Everything happens in the serialEvent() } void serialEvent (Serial myPort) { //Get the ASCII string: String inString = myPort.readStringUntil('\n'); if(inString != null) { //Trim off any whitespace: inString = trim(inString); //Split it into two strings at the space character String inStringValues[] = splitTokens(inString); if(inStringValues.length == 2) { //Convert to an int and map to the screen height/width float inByte1 = float(inStringValues[0]); float inByte2 = float(inStringValues[1]); println(inStringValues[0] + " " + inStringValues[1]); inByte1 = map(inByte1, 0, 1023, 0, height); inByte2 = map(inByte2, 0, 1023, 0, width); //raw the point stroke(255, 255, 255); point(inByte1, inByte2); } } }
The Processing code that runs on the computer reads the potentiometer values from the USB, converts them to screen x,y coordinates and draws a dot.
Anyway – here’s some other examples of far cooler Arduino projects.
An LED cube…
Little yellow drum machine…
Solenoid concert…
Really looking forward to playing with the Aduino some more and applying it to my second screen project.