tartelette / documentation demossource ↗

ws2812: addressable LED chain

A chain of WS2812, SK6812 or compatible LEDs on one data line, usually driven by a PIO state machine.

The data line is decoded the way the LEDs do it, from pulse widths alone: a high pulse shorter than 0.5 µs is a 0, longer is a 1. Every 24 bits is one LED, MSB first. The first LED keeps the first 24 bits, the second the next 24, and so on. The colours show when the line has stayed low for reset_us.

Because it only looks at pulse widths, the firmware's timing has to be in the right ballpark, as with real LEDs: a PIO program at the wrong clock divider produces garbage here too.

Keys

KeyTypeDefault
gpioGPIOrequiredthe data line
count1..40968LEDs in the chain
ordergrb | rgbgrbcolour order on the wire
reset_us1..1000050low time that latches the colours, in µs
mhz1..1000125core clock
[parts.rgb]
kind = "ws2812"
gpio = 14
count = 8

[panel]
rgb = { at = [0, 4], span = [4, 1], label = "LEDs" }

WS2812Bs latch after about 50 µs low; some newer parts (WS2812B-V5, SK6812) latch at 80 µs or more. If the firmware's reset gap is shorter than the part you are emulating needs, raise reset_us to catch the bug.

Panel

A row of lamps (or a grid, for a tall cell span).

Events

latch, with the number of LEDs updated, at each latch.

Not modelled

RGBW (32-bit) parts.