ws2812 LED library working
-
Just want to give some thanks to @robert-hh for the ws2812 library at
https://github.com/robert-hh/WS2812I tried some other libraries for neopixel and micropython but couldn't get them to work with the Lopy. But this one works a charm.
I connected an oscilloscope to the SPI pin and the issue seems to be signal timing. The faulty libraries are sending data with an equal high:low ratio, whereas the ws2812 documentation is clear that the ratio is something like 1:2 (low) or 2:1 (high).Anyway, I'm making progress now.
-
@livius Thanks. That looks fine. The biggest memory sinkhole is still this
tuple(self.duration)
. It is four times the size of the initial bytearray, since every element is stored as 4 byte integer, plus 32 byte header.
-
@robert-hh said in ws2812 LED library working:
It seems to have crossed with the change I made,
he he :) i have forked your repo some time ago and i miss that you changed it ;-)
I have "merged" now your change and introduce
resize
method to my class to be more flexible
now the nameimmutable
was removed and it become simplyWS2812
-
@livius Thank you for the change. It seems to have crossed with the change I made, dropping the usage of the (1,0)..... tuple totally. See:
https://github.com/robert-hh/WS2812/blob/master/ws2812.py
But you might have noticed that already.
Edit: I see that you pre-allocate the intermediate bytearray too. That seems reasonable since most of the time this class is used with a single LED array.
-
@robert-hh
I have looked at your good library and i have created immutable verisonWS2812_immutable
with less memory consumption.
https://github.com/livius2/WS2812/blob/master/ws2812.pyI do not have now leds to test but maybe it work without modification. Someone can test and send feedback
I will test it when i back to place with leds.only difference is that you must say how many pixels you have at start:
ws2812 = ws2812.WS2812_immutable(24, "P11")
-
@robert-hh There is a new version on github now which almost halves the memory required by the driver. Reducing it more would require a change in the rmt module also accepting arrays as argument. At the moment it's tuples only, which use a lot of space.
Edit: There is an SPI example of the driver, which uses way less space. But the timing is not very reliable. It disables the interrupt, which may cause a problem for long chains.
-
@johnmcdnz Indeed, the rmt version is quite memory hungry, due limitations of the rmt API. It should be possible to reduce that to a half, by not submitting the (1,0) tuple. I'll test that.
You should be able to connect the WS2812 to P2. The the onboard LED and the first LED in the external chain will have the same color. You should disable heartbeat then. Otherwise, the first heartbeat pulse will clear your chain.
-
@robert-hh I have your library working, however I find that the memory buffer is used up quite quickly. This limits operation to about 20 LEDs in a string. This is with a Gpy device.
Can you comment if you had similar experience? I'd like to know if there's a way to get the string upto 60 LEDs if possible.
Also out of curiosity, can the LED string be wired onto the PIN P2, i.e in parallel to the RGBled on the board? Not yet tried this.
Cheers, John McD.