Neopixel notes (Digital Systems)

Copyright © 2024 J. M. Spivey
Jump to navigation Jump to search

Neopixels (WS2812 leds) have a reputation for timing requirements that are difficult to satisfy. It's really not true, and with a bit of assembly language we can implement the protocol in a way that is totally reliable. As experiments done by others have shown it is enough to transmit bits with a period of 12.5 microseconds, with the signal high for slightly less than 1/3 of that time for a low bit, and slightly more for a high bit. On a 16MHz machine, we can use a period of 20 clock cycles, with the signal high for 6 or 14 clock cycles. The period cannot, however stretch to more than about 9 microseconds before there is a danger of the LEDs deciding that one frame is over an another is about to start.

The only real problem is that any pause in the bit stream will make the LED string reset and begin a new frame. That means we cannot really tolerate interrupts during transmission unless the interrupt handlers are really short and crucially we can be sure that more than one interrupt does not come at once.

The LEDs work fine with the 3.3V supply available on the edge connector of the micro:bit, but it's wise to avoid using them at an eye-burningly high intensity. With a good power supply, each pixel can draw up to 20mA for each of R, G, B, making 60mA per pixel or nearly 4A for a string of 64. This is likely to lead to overheating of the regulator that's embedded in the micro:bit's second chip.