Sunday, May 17, 2015

Controlling the WS2812B

I just got my 1 m, 60 WS2812 (or NeoPixel) strip form China and have been experimenting with patterns on them. My final goal is to wrap them around a circle or hexagon and have Fourier Transform bins mapped to the intensity of the LEDs. As a secondary function I plan to have the LEDs display a clock too.

The LEDs act like a shift register, just that the clock, data, and latch are all on one pin. The timing specification of the WS2812 (datasheet) is relatively straight forward. To save time, I've gone ahead and used the Adafruit NeoPixel library. I'll come back to try to implement the timing on my own when I'm done with this project, since this is for a class project and there is a deadline.

What I have noticed when using this sample code was that if I had too many computational cycles (e.g. I was looking up sin values from a lookup table) between each sendPixel, the data failed to properly clock out. I'm not sure if using a lookup takes longer than the maximum allowed time between bits, but something is causing the timing to be messed up. That's why using the Adafruit library is so handy; the data for all the pixels is stored in memory for easy adjustment of the colors and then clocked out with one command. This means one can compute and set the values first without worrying about it messing up timing. I could have also initialized an array for the first sample code to hold all the color data and clock it out, but I found it more convenient to use the Adafruit library. If I ever need to fully port my code to AVR C, I would go back to the first sample code.

No comments:

Post a Comment