pimoroni / pantilt-hat

Python library for the Pimoroni PanTilt servo and lighting HAT
https://shop.pimoroni.com/products/pan-tilt-hat
MIT License
112 stars 41 forks source link

RGB WS2812 LEDs do not work #14

Open veryalien opened 6 years ago

veryalien commented 6 years ago

A strip of 8 'standard' WS2812b RGB LEDs used as a light on a pan tilt hat just flickers random colours on the first 5 or 6 LEDs. I don't have any RGBW LEDs to use as a comparison test. This has been reported in the pimoroni forums by other users, but I don't think it has been resolved.

Gadgetoid commented 6 years ago

Looks like support for RGB is mixed- the ones I tested with (a small NeoPixel ring) still work, but certain variations do not. The WS2812s are driven directly by firmware on the PIC16F1503 which;

  1. Doesn't have much margin for tweaks
  2. Can't (easily) be updated in the field

I think it's safer for us to recommend a list of compatible LED products than to risk changing the firmware now, since I don't know what knock-on effect it might have on other WS2812 variants (present & future).

Fixing the code is problematic because the timings are so tight that the code to update the LEDs doesn't have anywhere really to go, briefly it looks like this:

for each colour channel
    for each bit in colour channel
        if bit is set
            write WS2812_DATA HIGH
            write WS2812_DATA HIGH
            write WS2812_DATA LOW
        else
            write WS2812_DATA HIGH
            write WS2812_DATA LOW

... yes, the only difference between a WS2812 1 pulse and 0 pulse is that the DATA pin is set HIGH twice in a row to increase its duration.

There's actually some loop unrolling, clever instruction ordering and other tricks that can improve this, but it's a delicate balancing act.