jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SK6812RGBW LED Strip not displaying correct colors

12pharoh21 opened this issue · comments

I am having an issue with my LED strip. This all started when I tried adding an LED strip to my Pi 3B+ to put some lighting in my 3D printer enclosure and the LED strip was giving me issues. I have been able to determine the issue is not with the strip, but I'm not sure where the problem is.

I have a Pi running Raspberry Pi OS that I'm using for testing right now, I have followed the steps for wiring the LED strip using a level shifter, I'm pulling 24V from my printers PSU to a buck converter and dropping that to 5V, and the signal is coming from the SPI pin on my pi.

Right now, I'm just testing a single LED at a time to see how everything is responding. It seems like the code is not aware that I'm using an RGBW strip. Here is my code:

import time
from rpi_ws281x import PixelStrip, Color
import argparse

# LED strip configuration:
LED_COUNT = 26        # Number of LED pixels.
# 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

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
args = parser.parse_args()

def colorWipe(strip, color, wait_ms=50):
    """Wipe color across display a pixel at a time."""
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms / 20.0)
        strip.setPixelColor(i, Color(0,0,0))
        strip.show()

strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_BRIGHTNESS)
strip.begin()

colorWipe(strip, Color(255,0,0))

I went through some other iterations of my code and made it so it cycles the color command to each LED set so I can see what happens with each one. I recorded a video of what's happening with the LEDs and uploaded to YouTube. The same command is being sent to each LED in the strip, but the results are not consistent, and not what I expect to see. When the command is sent to the LED, it's always turning on 2 of the colors. You can see in the video that it will sometimes light 2 of LEDs because of this. When it does that, it's turning on the White on one and Green on another. So I'm seeing Yellow (Red and Green), Bright White (White and Blue), Pink (Red and Blue), then White on one and Green on the next.

The second part of this is my first LED in the strip has the Green LED on all the time. I'm sure it's related to all of this, but I'm not sure what the problem is.

I have tried sending the Color code as (0,0,0,255) but that just shuts the LED off. Is there something I need to add to make sure it's using RGBW command set? Also, I'm pretty sure this strip should go in the GRBW order. Any help would be greatly appreciated.

I was able to get this resolved. The problem ended up being a culmination of a couple problems.

I was finally able to get the LED strip working properly with just a basic Raspberry Pi OS install by swapping out the level shifter (guess it was faulty), but then I was having issues with the LEDs receiving the first command to turn on a color then the every LED on the strip and all colors would come on and not shut off. This happened after I did a fresh install of Octoprint on the SD card.

I tested the hardware by swapping the SD card from the Pi that had the base RasPiOS install and it was working perfectly. So I installed Octoprint on that card and it did the same thing with turning all LEDs and all colors on. I found that after I loaded Octoprint onto an SD card even wiping it and reinstalling RasPiOS would do the same thing with the LEDs when I would test, so I'm not sure what Octoprint was doing to the SD card, but that was the only changing variable in this scenario.

I eventually got fed up and decided to test Octoprint and see what happens, and it turns out Octoprint is working perfectly now. Not sure why there is such an issue with trying to use the just the basic NeoPixel library from Adafruit when Octoprint is installed on the card, but as long as it's working within Octoprint, that's all I care about. Hopefully this helps someone in the future if they experience something similar.