A colorful globe with the WS2801 LED strip

25.1.2012
Looking for something nice that could be done with the WS2801 strips i bought, I came up with this idea to build a light globe. The arduino drives the strips and has a couple of programs it runs.

The best way to show how this all looks is probably some movies. (Beware, i used my cheap digicam to record, no high quality...). Some still pictures at the bottom.




The globe in action




Controlling the animation speed

Besides the challenge of physically building something that looks decent, writing the code was quite a challenge. I got reminded of the olden days so old I didn't even experience them properly. How to write code that fits into the ridicoulously small 2 kilobyte memory of the arduino?
I usually code PHP, where you don't care much about variable types, and memory is only relevant if you do really cricital things.

This globe is built from 10 0.5 meter strip pieces. With 32 leds per meter, thats 160 pixels. The array to give to the fastspi library alone eats away 3 byte per pixel. Then I implemented a particle system to control the effects. At some point, just nothing happened and after a while i figured that it was because the arduino ran out of memory. So i went to reduce the memory as much as possible. First i looked at the particles, because there are many instances of them. Changing int to byte saves one byte. I had like 5 values in 50 particles, saving me 250 bytes or more than 10% of my total memory.
Floats are even worse, because they eat 4 bytes. Finally, i managed to reuse the particle instances for the different effects that mainly differ by color, rather than instantiating two arrays of particles.

Another surprise was that the Arduino does not want you to use new. Instead of instantiating objects on the fly, my code now has a list of the objects it needs at startup and then does not allocate or deallocate any memory - which is certainly helpful to keep the program running without crash. Modern operating systems prevent fragmentation, but i guess the Arduino will not be able to do that, so after lots of allocate and deallocate even if you manage to not have memory leaks, you still could have fragmentation.

If you want to see how I do this, or reuse something, i made the code available at github.

ws2801 electronic art arduino