Monday, December 23, 2013

LED Strip Peakmeter using WS2812 aka Adafruit "NeoPixel" LEDs

(Unfortunately, the video doesn't do it much justice and it looks MUCH better in person)

This is a basic peakmeter I made using the Neopixel LED strips obtained by the adafruit store. If you haven't seen these before, they're pretty sweet because the driver circuitry for each LED is built into the LED itself and is controlled through a 1-wire serial protocol which can be daisy-chained through the whole strip. This means you can control the color and brightness of each LED individually using a single wire and you don't need any high current FETs on your board to do all the color switching.

The project currently consists of 3 parts and is a rather dirty way of doing it.

A C++ program gets peak meter data and prints it to stdout. This is piped into a python script which figures out the colors for the strip. This is then sent through serial to an AVR which then finally sends it through to the LED strip using the WS2812 serial protocol.

More details:

  • The C++ program running on windows uses the Peak Meter API included in Windows Vista and newer to get the system peak meter value and print it to stdout as an integer between 0 and 255.
  • The python script reads this number through command line redirection (a simple pipe) and figures out the color and brightness of each LED. It puts all these together in a very basic frame structure and uses pySerial for serial communication to an FTDI module which then speaks UART to an ATMega48 I have on a very basic devboard I made for myself a long while ago.
  • The ATMega48 waits for frames to come in and then pushes out the corresponding string of color using code taken from the Arduino library written by Adafruit to communicate with the WS2812 chips. Because of the strict timing requirements needed for the WS2812, it's rather tricky to get running on an 8MHz processor, and needs to be done in assembly. Luckily the good people at Adafruit had already provided this for free so I was able to use that without dealing with that mess myself. In the future I will probably just use a faster CPU as to not have to deal with that issue.

My future plans for this are to use the Audio capture APIs in windows to get the actual waveforms for audio being played on the system. Then I can do some fancier visualizations with several rows of the LED strips (spectrum analyzer, oscilloscope view, etc). Eventually it will be a continuous dance party in my apartment =p.

No comments:

Post a Comment