What is it?!
I was in B&Q a few weeks ago and this LED panel caught my eye. It’s not the type of thing I’d normally buy but I fancied its hacking potential as an ambient device of some sort.
Taking the back off revealed a set of nine mini circuit boards, each with a red, green and blue LED plus a simple circuit to cycle through those colours. The wiring couldn’t have been simpler – the 5V DC power supply ran to a switch with each of the LED boards wired in parallel from that.
At this point I didn’t know what I was going to use it for but I had a plan for taking control.
The standard behaviour for the lamps was to start at red, then sequence through to green then blue at a random rate. Taking control of each red, green and blue LED individually was more work than I was prepared to put in — on top of needing to wire and control 27 LEDs individually (via PWM outputs if I wanted smooth transitions) I’d also need to add resistors to limit the power going to each bulb. Far too much work for a couple of nights tinkering.
However, by simply controlling the 5V input to each circuit board I could have three-state control over each bulb: off, cycling colours, and constant red. The constant red can be achieved by removing the power for as little as 1 millisecond every couple of seconds. Every time the power trips the bulb resets to red (and the delay is imperceptible).
So, step one: I kept the ground (black) wire running between all of the lamps, but cut away the standard positive (red) wiring. I then soldered each positive connection to a jumper wire and from there directly to an output on an Arduino Uno board. The ground line went to ground on the Arduino. Since the power switch was no longer required I wired that as an input switch in case it would be useful later.
At this point I still had no idea what I’d use it for, but was able to write some simple sketches to control the individual lamps. All was well.
So what to do with a 3×3 ambient light?
I ran through various ideas including indicating weather forecasts, a count of unread emails, and any ‘ending soon’ eBay auctions. But in each case there would be a lot of bespoke coding required and, actually, the output would be pretty cryptic: “what does one red ball, two cycling balls, a flashing ball and four off balls mean again?”
So then I had an idea… could I display a text font on a 3×3 display? I had a hunt around for any fonts that would work on a 3×3 matrix. To my surprise I found a few and in the end I created my own font using some of the others as inspiration.
Some Arduino sketching later and I had the whole printable ASCII range mapped out in an Arduino array. Input via the serial line was printed directly to the display – result.
OK, so now it displays text, what next? Well, then I thought, “Is there a good existing API for handling small amounts of text?”. Twitter seemed like the obvious answer.
The Twitter angle
The benefits of using Twitter seemed pretty clear: the API is rock solid; there are clients for just about every platform I might want to send from (web, iPhone, SMS, etc); and it would be easy to hook it into other applications – like that weather forecast idea I’d had previously.
Putting it all together
Using the PHP OAuth library by Matt Harris it was pretty straightforward to get Twitter messages via the API. It can show anything that is available via the API, and right now I’ve settled for @ mentions for 9bulb. So if you send a message @9bulb it’ll pop up on my panel – sweet!
The one shortcoming at this point was that the messages ran across the panel in real time, even if I wasn’t there to see them. To fix that, I added a second ‘mode’ to the Arduino code.
In this mode the Arduino powers all lamps constantly, making it work just like it did when I bought it. But when a message comes in it’s held on the serial buffer and the lamps change to display a red cross to indicate an incoming message.
I then coded the old power switch to control modes: off for buffering, on for playback.
That’s about it. If you fancy trying it yourself the code is now available on GitHub: https://github.com/grantgibson/9-bulb
Thoughts for the future
Right now it’s a read-only Twitter client. A nice future enhancement would be to allow for the creation of messages directly on 9bulb. I don’t want to modify the case of the unit, but the power input socket is now free. It’s a 3.5mm headphone-style socket, so my current thinking is to have an external Morse code key which could be plugged into that 3.5mm socket. Messages could be tapped out in Morse and potentially previewed on the lamp display before sending.
If anyone wants to have a go at writing the sketch (and/or the PHP) for that I’d love to see it. There are several Arduino Morse input projects on the go, but I haven’t yet thought about how to handle both incoming messages and incoming dot-dash sequences in a single code loop. Thoughts on a postcard please.