The tutorial used a Pi 4 but the PWM library is incompatible with the Pi 5.
The Pi 5 uses the SPI port in a clever way to generate the required PWM signal.
The cycle time is 1250 ns (800 kHz).
A '0' bit is 0.4 high, 0.85 low (40:85 = 8:17 or roughly 1:2 ratio)
A '1' bit is 0.85 high, 0.45 low (85:45 = 17:9 or roughly 2:1 ratio)
This would be like transmitting 100 and 110 binary at 2.4 MHz.
The SPI sends 8 bits to represent a neopixel bit, so one could transmit
11100000 for a 'zero' (469 ns = 400 + 69 ns) 11111000 for a 'one' (781 ns = 800 - 19 ns)
which are within the 150 ns tolerance.
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI/releases/tag/1.0.9 uses:
frequency: int = 6400000,
reset_time: float = 80e-6,
bit0: int = 0b11000000,
bit1: int = 0b11110000
which are slightly shorter pulses.
The R-Pi could use an SPI clock rate between 5.715 and 7.272 MHz to satisfy the neopixel cycle times. The code snippet above indicates 6.4 MHz SPI clock rate, for 800 kHz neopixel rate.
I think it might be possible to get better ratios by sending groups of 9-bits which overlap the 8-bit bytes. If 3 bits = 400 ns, 9 bits are 1200 ns, 8 bits are 1067 ns = 937.5 kHz byte rate and 7.5 MHz SPI clock rate. The price is more work bit packing.
If one is prepared to pay that price, one might as well reduce the SPI clock rate to just three times the neopixel bit rate and reduce the packing from 9 to 3 SPI bits per neopixel bit.
There are 24 neopixel bits per RGB chip, 8 neopixel bits per primary colour LED.
The library has only one demo, neopixel_spi_simpletest.py which is not as impressive as the PWM library demos.
The WS datasheets seem to be a bit vague about timing, so this person did some research to see what exactly did work:
https://cpldcpu.wordpress.com/2014/01/14/light_ws2812-library-v2-0-part-i-understanding-the-ws2812/
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.