This feat is accomplished with a very timing-specific protocol. Since the protocol is very sensitive to timing, it requires a real-time microconroller such as an AVR, Arduino, PIC, mbed, etc. It cannot be used with a Linux-based microcomputer or interpreted microcontroller such as the netduino or Basic Stamp.
How the protocol works can be found in the WS2812 data sheet. For each RGB Led a stream of 24 bits will be sent, 8 bits for each color. The value of each bit, 1 or 0, is determined by the timing of the square wave.
A logic 0 is represented by a signal that is high for .35 mircorseconds followed by a low of .8 microseconds
A logic 1 is represented by a signal that is high for .7 microseconds followed by a low for .6 microseconds
So just in the process of updating a 16 LED RGB ring you will be sending 48 bytes of data, 3 bytes for each leds RGB value. Each byte contains a value of 0-255 indicating the value of intensity for that particular color (Red, Green or Blue).
Looking at the diagram above the transmission starts with D1 receiving the first 24 bits. After that D1 will pass subsequent bits on to D2. Once D2 receives it's 24 it starts passing subsequent bits onto D3. Note that this is different than usual shift register operation. The passing on will continue until the data line is held low for 50 microseconds. Holding the data line low for 50 microseconds is a reset code indicating next sequence is for the WS2812 to process.
Below is the code and a video of my setup. Codebender allows you to peek into the library files by holding down the CTRL key while clicking on the library header file. In this case you would hold the CTRL key and click on "Adafruit_NeoPixel.h". This will open a new tab with the NeoPixel library and related files. From there look on the left hand side and select the Adafruit_NeoPixel.cpp file to explore and learn more about this awesome library.
Don't be afraid If you have any questions please feel free to ask.
No comments:
Post a Comment