Experiments in wearable electronic art.

SD cards, streaming animation, and bit-banging


It was an eventful weekend. I built a new prototype rig from an Arduino Mega2560 (the very same Mega that was in my Anthrolume 1.0 suit), because I was going to run out of I/O pins on the Arduino Uno after adding the hand controller, mode LEDs, and XBee radio. Additionally, the Mega has 8KB of RAM, enough that I can keep a record of the colors of all the LEDs in memory, which facilitates some features I want such as drawing moving text across my body.

One of the technical hurdles for Anthrolume 2.0 was figuring out how to use an SD card reader and CoolNeon lights at the same time. The problem lies in the fact that they both want to use the SPI (Small Peripheral Interface) bus on the Arduino, but the CoolNeon lights sort of want that whole bus for themselves.

I designed some digital logic using tri-state buffers that would allow me to switch the SPI bus between the SD card reader and the light strand under the control of one digital pin on the Arduino. But I didn’t really want to add that logic wart if I could find another way.

The “other way” is to hook the light strand to a couple other digital pins and “fake” the SPI protocol. “Faking it” in this case is a technique called “bit-banging.” The idea is that you simulate a protocol (in this case a simple clock-line/data-line setup) by manually setting the logic state of a couple Arduino pins very quickly.

On Sunday I got this approach to work. It allows me to read from the SD card using SPI and write to the LED strand manually via bit-banging. At first I found bit-banging to be quite a bit slower than the hardware-accelerated SPI provided by the Arduino, but by using the badass digitalWriteFast library I was able to achieve frame rates of 95 fps with 50 LEDs. That will give me up to 40fps for my production strand of 250 LEDs – easily enough.

I wrote a very simple C# program to emit two pre-canned animations to files. The files consist of RGB tuples x 50 LEDs x some number of frames. Later I’ll beef up the .ani files to include metadata, musical synchronization information, etc. I used that program to write two 37K animation files to an SD card and loaded that SD card into the Arduino’s external SD card adapter.

The video below demonstrates me reading animation frames from the SD card and streaming them to the strand in real time. This is a big technical milestone for Anthrolume 2.0!

Author: regenesis

Seattle New Media artist.

2 thoughts on “SD cards, streaming animation, and bit-banging

  1. Great progress! I hope you will be sharing your code. Have you thought about adding lights on your shoes? I’m going to try to put together a small shoes-only project (with tilt or pressure sensors in the shoes for timing). I just ordered a strip of addressable RGB LEDs which I think will work better on shoes than the CoolNeon lights. I look forward to seeing Anthrolume 2.0 evolve.

  2. Thanks Scott! Yeah I’d be happy to share my code. The bit-banging part is largely distilled down to a single function that writes the entire strand in one go. I will do a post on that specifically, since it was half a day’s work to get to to be efficient.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s