WS2812B LED Protocol and LED Microcontrollers

Veröffentlicht von

In the last few years, programmable LED lights like the WS2812B LED have taken the illumination world by storm. These tiny modules pack separate red, green, and blue LEDs into a 5mm x 5mm, package, and they also contain a control chip so small that it's hard to see with the naked eye. This tiny chip receives an input, subtracts its own signal, and passes the remaining data to the next module in the chain. The process repeats until that single data line lights tens, hundreds, or even more than a thousand LEDs.

Learning how to connect a WS2812 LED strip to an Arduino board is simple. You'll need:

1. One data line

2. Power source

3. Ground

Once you've sorted out the hardware, you can utilize several libraries to allow your microcontroller to control illumination. But how does this work? How can one little data line control so many LEDs?

programmableLED_IMAGE 2

WS2812B protocol

CH1 binary signal from the microcontroller containing 48 bits to control 2 WS2812Bs. Only 24 of these bits are passed along as CH2.

To understand these LEDs, let's walk through how this addressable LED protocol works. Each separate red, green, and blue LED in a single WS2812B unit is set up to shine at 256 brightness levels, indicated by an 8-bit binary sequence set from 0 to 255. When combined, each LED unit requires three sets of eight brightness bits, or 24 bits, of information for full control. Here's a quick guide to the process:

1. A microcontroller transmits this sequence of eight green bits, eight red bits, and eight blue bits to the first LED in the series.

2. When multiple LEDs are present, the data sequence that controls the second LED starts directly after the first with green, red, and blue data. The sequence continues in that pattern until it illuminates every LED present.

3. The first LED takes in information for the entire chain of LEDs, then passes the same data along without the sequence it applied to itself, transforming the second LED into the first component on the list (as far as it knows).

4. This "new number one" LED unit continues passing information along until there are no more binary LED sequences left.

The image above shows a microcontroller input signal to a WS2812B unit as CH1, where long pulses indicate high signals and short pulses indicate low signals (more on this later). This works out to a 24-bit sequence of 100101100000000000000000, meaning a "10010110" value for green — 150 when converted to decimal — and zeros for the remaining 16 bits. The resulting color is the medium brightness pure green value you see in the image above, with no red or blue mixed in.

Both WS2812 LED units are the same color here, so the CH1 sequence repeats itself and passes along this same data to CH2. The second sequence (and resulting color), could be different depending on the user's desired effect. Zooming out on this type of signal below, we see a comparatively long gap before the next set of color signals transferred.

Microcontroller for LED Lighting

Representing each number's value with ones and zeros is easy enough to understand, but how does a microcontroller actually convey that information to the first LED unit? In this protocol, each one or zero has its own on/off timing sequence. To signify a one or zero, an LED microcontroller does the following:

1. Holds the line high for a specified amount of time

2. Allows it to go low for a corresponding amount of time. In total, that time will add up to 1.25us±150ns (±.150us). Per this datasheet, high/low values are:

- One is indicated by: .8us high, .45us low

- Zero is indicated by: .4us high, .85us low

Therefore, if you want to send a binary signal starting with "101," you'd send the following:

- .8us high, .45us low (1);

- .4us high, .85us low (0);

- .8us high, .45us low (1).

This process continues for 21 more bits, directly followed by the next LED unit's sequence. Eventually, the microcontroller sends a reset low signal (300us or greater) to indicate it's time to start over. The most significant bit goes first, and each signal includes leading zeros to ensure that there are eight bits total per GRB color element.

If you want to dive into programming WS2812B LEDs more directly, note that this level of control is well out of the range of "normal" Arduino programming. You'll need commands such as:

1. delay()

2. delayMicroseconds()

3. millis()

4. micros()

To manage this level of control, assembly programming becomes essential. While interesting, assembly programming also throws a new level of complication into your coding work. The good news is that you can find multiple libraries that deal with using these devices, making it easier to explore LED programming without extensive experience.

WS2812B LED Recap: A Few Notes

Be aware that WoldSemi's popular datasheet contains an error. The datasheet states that the high/low values are .9us and .35us. As the tolerance here is ±150ns (.150us), and each combination adds up to 12us anyway, both should still work, but it's something to keep in mind.

programmableLED_IMAGE 3-crop 

LEDs reset code at ~1000us

Another possible issue comes with a change from 2017. New WS2812B LEDs started to appear, requiring 300us reset times instead of the 50us we discussed earlier. The concepts presented here will still apply with this time change, but if you're going to construct your own interface on a very low level, consider yourself warned. The zoomed-out sequence shown above indicates a generous reset time sent to the LEDs of around 1000us, or a full millisecond.

programmableLED_IMAGE 4-crop

programmableLED_IMAGE 5-crop

Variation in input and output signals

As you can see in the images above, the white CH1 signal is the input from a microcontroller, and the yellow CH2 is the output from a WS2812B LED. The input high signal is .815us, but the corresponding output is .620us in duration. This would indicate that the WS2812 isn't merely passing signals along, but is actually transforming them into a certain timing value. It also appears to be out of spec.

As the second LED in the chain glowed green, this low value appears to work properly. But when I programmed the sequence to pass data to a third light, the LED flickered. Admittedly, this could have been a result of my soldering setup or another factor not directly related to the timing itself.

Programmable LED lights may vary based on their manufacturer and build, but the basic binary sequence concept appears to be consistent. You may never have to worry about how the lights work for your applications, but it's an interesting concept to explore. With a little background knowledge, you might gain inspiration for unique and interesting future designs.


Neue Beiträge

Leider ergab Ihre Suche kein Ergebnis

Aktuelles über Elektronikkomponenten­

Wir haben unsere Datenschutzbestimmungen aktualisiert. Bitte nehmen Sie sich einen Moment Zeit, diese Änderungen zu überprüfen. Mit einem Klick auf "Ich stimme zu", stimmen Sie den Datenschutz- und Nutzungsbedingungen von Arrow Electronics zu.

Wir verwenden Cookies, um den Anwendernutzen zu vergrößern und unsere Webseite zu optimieren. Mehr über Cookies und wie man sie abschaltet finden Sie hier. Cookies und tracking Technologien können für Marketingzwecke verwendet werden.
Durch Klicken von „RICHTLINIEN AKZEPTIEREN“ stimmen Sie der Verwendung von Cookies auf Ihrem Endgerät und der Verwendung von tracking Technologien zu. Klicken Sie auf „MEHR INFORMATIONEN“ unten für mehr Informationen und Anleitungen wie man Cookies und tracking Technologien abschaltet. Das Akzeptieren von Cookies und tracking Technologien ist zwar freiwillig, das Blockieren kann aber eine korrekte Ausführung unserer Website verhindern, und bestimmte Werbung könnte für Sie weniger relevant sein.
Ihr Datenschutz ist uns wichtig. Lesen Sie mehr über unsere Datenschutzrichtlinien hier.