HardFOC driver · ESP32
WS2812 RMT Driver¶
A C++ driver for WS2812 and WS2812B addressable LEDs (NeoPixels) on the ESP32 family. It keeps a pixel buffer, scales brightness, encodes every bit as an RMT symbol and lets the RMT peripheral time the pulses, so the CPU never bit-bangs the line. Animation effects and multi-strip coordination come with it.
The driver is ESP-IDF code. Unlike the other HardFOC drivers it has no platform port: it calls ESP-IDF's RMT driver directly, so it runs on ESP32 chips with an RMT peripheral and ESP-IDF v5.3 or later, and nowhere else. Porting explains what that means for other targets.
- Interface
- One data line, NRZ at 800 kbit/s; 24 bits per LED, green-red-blue, MSB first
- Bit timing
- T0H 0.4 µs, T1H 0.8 µs, T0L 0.85 µs, T1L 0.45 µs, each ±150 ns; reset: low for more than 50 µs (the driver sends 300 µs, enough for the WS2812B-V5)
- Supply
- VDD 3.5 V to 5.3 V
- Input levels
- High at 0.7 × VDD or more, low at 0.3 × VDD or less: 3.5 V and 1.5 V at VDD = 5 V
- Package
- 5050 (5.0 mm × 5.0 mm), 4 pins: VDD, DOUT, VSS, DIN
- What the driver uses
- One RMT transmit channel at 10 MHz (100 ns per tick), one GPIO, a blocking transmit per frame
What you get¶
- One object per strip.
WS2812Stripowns an RMT channel, the pixel buffer and the timing;SetPixel()andShow()are the whole loop. See the API guide. - Hardware timing. Each bit becomes one RMT symbol with the high and low times you configure, in 100 ns steps. See Signal timing.
- Brightness without losing your colours.
SetBrightness()scales at send time; the stored pixels stay as you wrote them. - RGB and RGBW. 24 or 32 bits per LED, chosen per strip.
- Effects. Rainbow, chase, blink, breath, Larson scanner and solid colour, one
Tick()per frame, andWS2812MultiAnimatorto keep several strips in step. See Architecture. - Tested without hardware. Host unit tests run the real driver sources against a recording fake of the RMT driver. See Testing and CI.
Where to go next¶
-
Wire a strip, add the component, light it in about 15 lines.
-
Pins, level shifting, power and the bit timing from the datasheet.
-
From pixels to RMT symbols: the layers and what each one owns.
-
Create a strip, set pixels, animate, handle errors, task by task.
-
Ticks, frame time, memory and the reset gap.
-
Every class and member, generated from the headers.