Doubling the LEDs
From Open Source Urbanism
In order to display text on both sides of the bicycle wheel we will need to add another row of LEDs. We could connect these in parallel with the existing LEDs, having them turn on and off at the same time. This however would mirror the image and render the text in reverse. A better solution would be to add additional controls for the new LEDs.
15 Digital Pins
Adding an extra 7 LEDs to the 7 we already have means we need 14 pins to control the LEDs plus an additional pin for the save button - a total of 15 digital pins. The Arduino has 14 dedicated digital pins and 6 analogue input pins. It is possible however to use the analogue pins as digital in-outs, they behave just like the other digital pins (as detailed here). To use an analogue pin as a digital I/O you simply set the pin to operate as an input or output and write or read from the appropriate pin number. The procedure for this is the same as for the regular digital pins, i.e.
pinMode(14, OUTPUT); digitalWrite(14, HIGH);
The pin numbers corresponding to the analog pins are 14 through 19.
Moving to a Really Bare Bones Board
One of the greatest things about using the Arduino as a development platform is that it's available in a large variety of board designs - the Arduino site has photos of all the official builds. Due to the open-source nature of the platform there are also numerous Aduino-compatible boards on the market. These third party boards often go by the name Freeduino and are generally cheaper than those manufactured under the Arduino brand name.
We decided to give the Modern Devices Really Bare Bones Board a try. This board saves on component count and space by removing the USB controller and relying on a special USB to TTL serial cable for uploading sketches. Measuring just 76.2 x 15.5mm (56.6 x 15.5mm without power jack and voltage regulator) it is, as the site claims, "the smallest and most low-cost Arduino-compatible available right now". The board is available pre-assembled or in kit form - we got 10 kits for US$100.
The kit is a cinch to put together. We're going to experiment with running the project from 2 or 3 AA or AAA batteries so we omitted the voltage regulator and power jack; without these items on the board, component count is in single figures. The RBBB kit comes with two rows of header pins, the equivalent of the header sockets on the Arduino Diecimila. After assembling the board we soldered it directly to a small 65 x 45mm experimenters PCB (the same as we've been using for previous shield prototypes). This board was large enough to hold two rows of 7 LEDs (front and back), the save switch, Hall effect sensor, battery clips for 2 AAA batteries, and an on/off slide switch.
When building this version I remembered something Beatriz da Costa mentioned at the ANAT Still Open workshop, that the Arduino microprocessor was probably better able to sink current to ground then supply current through the output pins. For this prototype I've decided that all LEDs shall be connected between the supply voltage and their output pin (via a 150 ohm resistor). To turn the LEDs on each output pin is driven LOW (to turn them off the pin is driven HIGH).
I have also altered which pins are used to drive the LEDs. The Arduino uses pins 0 and 1 for serial communication, this includes when the USB cable is used to connect to the computer. I found when components were connected to these pins (LEDs, buttons, etc.) they interfered with data transfer. In order to prevent this I decided to leave pins 0 and 1 free. Pin use is now as follows:
pins 2-8: right hand side LEDs
pins 9-13, 15 & 16: left hand side LEDs
pin 14: save button (push switch connected to ground)
Analogue pin 5: Hall effect sensor
In the pervious builds I had the save button connected to 5V with a pull-down resistor but I have since discovered that the Arduino microprocessor comes with inbuilt pull-up resistors. To activate the pull-up resistor on a specific pin you use the digitalWrite() function to turn an input pin high. This negates the need for an external resistor. The save button is now connected using this method; when pressed it connects to ground.
Code for the double sided prototype is available here: Bike_POV_Beta_7
This code simply mirrors the data across both sides of the wheel, hence one side (the left) appears reversed. The next step will be to correct this so that both sides of the wheel display readable text.
Doubling the Display
Getting the text to display correctly on both sides of the wheel required a significant rewrite. There were two major obstacles to overcome with the existing code: how to step through the text string one character at a time in both the forward and backward direction, and how to reset/restart the text string at different times on either side of the wheel. I choose to solve these issues by introducing a number of variables for both the left and right side of the wheel and by changing the loop() function so that it prints individual rows of LEDs rather than whole characters. The variables keep track of the character position in the text string and the row position within each character. A separate set of variables keep track of the reset time for the left and right display.
While I was getting this to work I did a cleanup of the code. With a focus on reducing memory usage, I changed a number of the variable types: the LED pin numbers are now declared as bytes and many of the constant integers are now set using #define. The compiler replaces references to defined constants with the actual value at compile time, this means they don't take up any program memory space during run time.
Pin numbers have changed again, due to the construction of another prototype (see the next section for details). The new pin setup is as follows:
pins 2-8: right hand side LEDs
pins 9-15: left hand side LEDs
pin 16: save button (push switch connected to ground)
Analogue pin 5: Hall effect sensor
This set up works well with the Modern Devices board, there probably wont be any further pin changes.
The project also has a new name: Spoke-o-dometer.
The new code is available here: Spoke-o-dometer_Beta_8

