I recently bought some Arduino microcontroller/prototyping boards and components. The plan is to rediscover my childhood interest in electronics and familiarise myself with these tools so that maybe in future I can help teach some of this at schools. This is because I believe that its the practical stuff that can integrate with other school lessons that can give young people the best start at programming.
The great thing is that actually, with only a little knowledge, doing this stuff is really easy. The Arduino board designs and software are open source, which is a good thing. However as usual this means the docs can be problematic.
There’s a confusing array of Arduino hardware out there. The boards have the ATmega micro controller chips on them that you program, and lots of digital and analog input/outputs so you can control and measure things. There are boards with Ethernet, Wi-fi, USB and even LED matrix drivers.
Basic Arduino (UNO)
Using this Arduino which has just a USB port and the I/O connectors, plus a bread board and 4-digit 7-segment LED display from an Earthshine starter kit, I managed after digging out the spec sheet on the display, to create a counter from 0001 to 9999. This sounds trivial, but it has a few challenges:
- The LED display is basically 4 x 8 LEDs (7 segment + decimal point)
- There are only 12 pins on it. Huh?
- If you don’t send power to one of the LEDs, it goes off.
The spec sheet showed that 4 pins control which of the 4 digits you are addressing – set them LOW (common cathode) to enable the corresponding digit.
Then you set some of the other 8 pins HIGH to represent the digit or symbol you want to show.
So to set all 4 digits without any shift register chips or other smarts to “remember” the state of segments for each digit, you have program the Arduino to continually loop through the 4 selector pins, set the segment pins HIGH, wait a few milliseconds, then set the selector pin for that digit HIGH (to turn it off), and then repeat the same process for the next digit’s selector pin. What happens is that each digit is illuminated for say 5ms and then it moves to the next one.
They are continually going on and off, but because you constantly loop at high speed over them, it appears to be a continuous display.
Much more fun – the Rainbowduino
The Rainbowduino is a self contained Arduino board and the latest v3.0 one has built in mini-USB. So its just like an Arduino UNO but has a bunch of other controllers to drive an 8×8 RGB LED matrix with constant current (which I think means when lots of LEDs are on, they stay the same brightness). CAUTION: the LEDs are also seemingly as bright as the sun and staring at them is likely to leave you with a disturbing 8×8 grid of dots burnt into your retina.
So I bought the Rainbowduino plus an 8×8 RGB LED Matrix. The Rainbowduino is built to have the matrix directly plugged into the top of it, which is very handy.
There are some tricks to getting this working however:
- Unlike the Arduino UNO, my Mac would not recognise the Rainbowduino when plugged in to USB. I had to install the “FTDI” drivers from here. Thanks to @andydavies for the tip there
- The docs on Rainbowduino are sketchy, and seem to be mainly targeted at an LED 3D cube rather than the matrix, and using the Processing language (which is not what the Arduino IDE uses).
- It turns our there are several options for controlling this matrix. You can flash your own Arduino “sketches” (programs) directly onto the Rainbowduino, or you can use the I2C serial protocol to drive the Rainbowduino from another Arduino – I am guessing this means the Rainbowduino ATMega has a custom boot loader that supports serial comms to drive the display. I may be wrong.
To solve (2) I had to find the driver code that would work with the Arduino IDE. The v3 Rainbowduino driver is here. If you save that to ~/Documents/Arduino/Libraries/Rainbowv3 or similar (for Mac OS X at least that is where it is) and restart Arduino IDE, you will see you can now insert it into your Arduino sketch using the “Import Library…” menu option.
You will then find it does not compile, complaining it cannot find “WProgram.h”. This is I think because the library is built to run with “Wiring” programming language. To fix this you need to edit the Rainbowduino.h file from the driver that you saved, and change the #include <WProgram.h> to <Arduino.h>.
After that you can use the driver, which is incredibly simple:
- in setup() call Rb.init()
- in loop() call some Rb methods such as: Rb.blankDisplay() and Rb.setPixelXY(x, y, rgbcolour)
Why so dark? LEDs are too bright to photograph without a filter. I put lots of tissue paper over them.
So here’s an example to apply the colour spectrum diagonally to the entire grid in action:
Note that if you find your reds are not working you probably have a C typing problem, and need to explicitly cast your values to uint32_t to avoid the RR of your RRGGBB being lost to 16bit accuracy.
And seeing as most of my life is spent in Grails… this wouldn’t be complete without a video of the Grails cup shining in all its 8×8 glory.
And here’s the code, if you want some Grails glory yourself: