jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.76k stars 616 forks source link

First LED green - RPI CM4 SPI #469

Open eRkoDev opened 2 years ago

eRkoDev commented 2 years ago

Hey all, hey all, I drive 145 leds WS2812 using SPI on RPI CM4, but all time i have first LED in string green (LED is ok, i try other string). If i check signal on oscilloscope i see that MOSI is held high a that make a bit shifted.

Voltage levels looks good MOSI log1 - 4,5V, VCC 5

What i do wrong?

# LED strip configuration:
LED_COUNT      = 145      # Number of LED pixels. 145
#LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53

# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL,ws.WS2812_STRIP)
# Intialize the library (must be called once before other functions).
strip.begin()
GiyoMoon commented 1 year ago

Hey I had the same problem in my project. I'm using a Mango Pi MQ Quad and it seems like the SPI is held high (Which wasn't the case when using a Raspberry Pi 4 Model B). This resulted in the first LED always being green.

I solved it by sending an additional empty byte at the beginning. Have a look at my code here

This probably also need to be done here, or maybe the SPI can be configured to be held low? But I haven't found anything about this yet.