This project was done to have a Halloween costume that "fit my style". I wanted something representative of my geek-tendencies. The end product is small but technical with respect to a normal costume.
Design:The basic premise is that an Arduino Nano controls 2 16-bit IO expanders over I2C to PWM 32 LEDs (arranged in a circular pattern) into any configurable pattern desired. An additional 6 LEDs are driven directly from the 6 PWM outputs of the Nano itself.
The LED arrays rest behind the fabric of whatever shirt I would choose to wear, and the headers that the Nano uses to connect to the board hosting the LEDs bridges through the fabric to both hold the system in place and also proudly display the Arduino to the world
The power for the system is input through a mini USB connector at 5V, such that any portable USB charger can run the system. It is cabled beneath the fabric to hide cables. This wasn't terribly comfortable, but it got the job done!
Implementation:All this functionality was implemented and the LED positions were calculated in a spreadsheet (Spreadsheets are wonderful). The PCB was laid out in a 3" diameter circle, centering the Nano headers:
I had the board fabricated overseas. 2-sided with no special fabrication requirements and plenty of lead time made it quite affordable, even with black solder masking :D
I hand-soldered the pieces on (I had a microscope so even the 0402 resistors and the SMD I/O expanders weren't bad at all). I did find that I needed an additional PU resistor for the SCL/SDA lines of the I2C interface (operating at 400 kHz), so I spliced those in manually. Finally, I wrapped up the electrical work with a push button on the Arduino itself (2x3 header, pin 1 to pin 6) to be able to cycle through patterns
I finished it out at a mechanical system level with a few pieces of foam to offset the PCB from myself to avoid short circuiting anything out
Programming:The fun part! Given the processor speed on the Nano and the interface I had chosen (I2C), I needed to be creative on how to optimize the update rate of the LEDs to achieve a truly imperceptible PWM dimming. The first logical step was to speed up the I2C bus to 400 kHz. This was a simple internet search and register write, but not wholly sufficient.
My initial attempt of calculating the pattern and dimming values between each and every write to the LEDs turned out to be too intensive for the poor processor so, through some external advice, I opted to buffer the patterns in an array. 32 LEDs with 32 8-bit value states comes to a total of 1kB of RAM, which is 50% of the available space, so it works out as long as I don't add a bunch of other things in.
I then created a software sawtooth wave comparator to handle the PWM logic. Since < vs > operations are quick, it was easily handled by the processor. I then added a simple timer to handle progression through the pattern, and voila, I had an algorithm simple enough for the processor to run.
I implemented a variety of pattern functions, from simple decaying swirls and randomized starburst pattern to a linearized "swipe" across the polar LED pattern. The pattern was changed by pressing the button (SW debounced) which then reset all the values in the 32x32 array and then resumed the PWM and pattern progression logic.
Further work:I sourced enough parts to make 3 of them and ultimately decided to use another set to make an RGB variant. I programmed in some "disco-themed" patterns and put it in a carved pumpkin for a bit of pumpkin spice fun
The design needs to be updated to reflect the needed pullup resistors, but I haven't enough interest to make it happen. Ideally, a SPI controlled CC LED driver configuration would reduce the processor load and allow for other interesting possibilities, like accelerometer input or wireless connectivity. Putting in a battery would also ease the system strain of having a cabled portable power pack tethered to you at all times. All in all though, it turned out as well as I had hoped!
Comments