adafruit / Adafruit_CircuitPython_NeoPixel_SPI

SPI driven CircuitPython driver for neopixels.
MIT License
21 stars 11 forks source link

Make Frequency a Parameter to run Neopixels at 400 kHz (WS2811) or 800 kHz (WS2812)? #19

Closed geekmomprojects closed 4 years ago

geekmomprojects commented 4 years ago

Hi, I was trying to run some PTH Neopixels with the CircuitPython library, but the timing was off because the PTH neopixels, which were the WS2811 kind run at 400 kHz, while most WS2812 neopixels run at 800 kHz. By changing the FREQ parameter from FREQ = 6400000 to FREQ = 3200000 in this library I was able to run the WS2811 neopixels correctly, but I had to modify my own copy of the library to do it. Is it possible to create a parameter, as in the Arduino Neopixel library that lets the user change the neopixel signal frequency in the code, if desired? Happy to attach more information if needed. Thanks! Debra (GeekMomProjects)

ladyada commented 4 years ago

sure, those are pretty rare fyi - so the default would still be 6.4mhz. please submit a PR if ya can!

geekmomprojects commented 4 years ago

sure, those are pretty rare fyi - so the default would still be 6.4mhz. please submit a PR if ya can!

Got a different solution which identifies the problem as a timing bug. Fixing that bug allows the code to run simultaneously on the PTH Neopixels and the more standard ones, which the 400kHz/800kHz change didn't do. There is a description of the problem/solution in this Twitter thread (https://twitter.com/Bornach1/status/1301087477034344449?s=20), and I will make a PR to solve the problem. Thank you!

geekmomprojects commented 4 years ago

It turns out that I didn't need the 400kHz timing after all to solve my problem. I don't know whether adding the 400kHz/800kHz parameter would still be useful for anyone. I won't make a PR request for that specific change unless you think it would be a useful addition.

caternuson commented 4 years ago

Are 400kHz supported by the standard Neopixel library? If so, we should match how that is done here, in terms of user configuration.

The Arduino lib has a slightly different approach, combining pixel order and frequency into a single parameter called type. https://github.com/adafruit/Adafruit_NeoPixel/blob/3c2902a988b7ab72e3d90fd87cb2d79ed22d017b/Adafruit_NeoPixel.h#L205

caternuson commented 4 years ago

Closing. Should be fixed by #22