Addressable RGB LEDs
RGB LEDs on one wire, as a strip or a 16 wide panel.
- 4 pins
- 3 properties
Every one of its 4 pins
What it does
WS2812B LEDs, sold as NeoPixels, put a red, green and blue LED and a small controller in every pixel and chain them all on one data wire. There is no clock: each bit is a high pulse whose length is the bit, about 0.4 microseconds for a nought and 0.8 for a one, twenty-four bits a pixel, green first, and fifty microseconds of quiet makes every LED take up its new color at once. Mokxi’s part decodes those pulses from the pin’s own edges inside the datasheet’s timing windows, and abandons a frame it cannot read the way a real strip does. The same part is a strip, a ring or a matrix, up to 1024 LEDs. Because the timing needs a fast core, the WS2812 driver and the Adafruit_NeoPixel calls run on the ESP32-C3 and ESP32-C6 here. Power draw is not modeled, so a long strip never browns out a board.
How to use WS2812B NeoPixels with an ESP32
DIN to a GPIO, VDD to 5 V, VSS to GND, and a ground shared with the board. The Adafruit_NeoPixel calls compile as they stand: create the strip with its length and pin, set colors with setPixelColor(), and call show() to send them. Keep the brightness down on a real strip, because each pixel can draw up to 60 milliamps at full white.
On a real Arduino Uno the Adafruit library drives WS2812s with hand-timed assembly. In Mokxi the WS2812 driver needs a faster core, so it runs on the ESP32-C3 and ESP32-C6.
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels(8, 4, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.show();
}
void loop() {}The 3 properties you can set
What is true about the Addressable RGB LEDs, here
What is modeled
layout = "ring" bends the same row of LEDs into a circle, LED 0 at twelve o'clock
and the rest clockwise, exactly how the rings people buy are numbered. A ring is a
strip electrically, so nothing about the wiring or the firmware changes, only the
picture does. Nothing is shown until the latch: 50 microseconds of a quiet line ends
the frame, and every LED takes up its new color at once, the way a real strip does.
Not modeled
No brightness curve beyond a straight RGB value, and no power draw per LED, so a strip here never browns out a board's supply the way a long real one can.
The decode is the datasheet's windows. A high pulse under 125 ns is a glitch and is ignored; from there to 600 ns is a nought and from 600 ns to 950 ns is a one, 950 ns being T1H at the top of its ±150 ns tolerance. The low between bits is checked too (at least 300 ns after a one and 700 ns after a nought, both the bottom of their tolerances), and a stream that breaks either rule abandons the frame, the way a real strip stops following one it cannot read. The total bit period is not checked on top of that: the datasheet's own figure is 1.25 us ±600 ns, which constrains nothing once both halves are, and real strips take faster streams than 1.25 us happily. The 300 ns of forward delay per device is modeled as a flat 150 ns.
The latch is 50 microseconds of quiet, which is the original WS2812B figure; a WS2812B-V5 wants 280 microseconds, so a driver written against this one can produce a frame that never latches on newer strips. The color order is fixed at GRB (there is no RGBW and no way to say a strip is wired otherwise), and there is no per-LED refresh, no gamma, no thermal limit and no maximum of anything except the 1024 LEDs one part will hold.
From WS2812 addressable LEDs, in full.
See the Addressable RGB LEDs in a project
Shown here on: ESP32-C3-DevKitM-1, ESP32-C6-DevKitC-1
Where it turns up in a lesson
In a learn article
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Addressable RGB LEDs
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.