Background
I'm trying to control a single WS2812b LED strip from a Raspberry Pi. I've followed this tutorial from raspberrypi.com (with the exception of Prep & Installation step 4, because I couldn't find snd-blacklist.conf
).
That didn't work, so I also tried this tutorial (which involved adding a Logic Level converter), and when that didn't improve things, a few other tutorials/videos, all to no avail.
Code & Output
The first tutorial got the closest. It had me use this github library, where I eventually ran strandtest.py
. It appeared to partially work, but not entirely. I wasn't sure (and I'm still not) if this is a hardware or software issue, so I reduced the code to the minimum possible where it still turns on at least one LED.
import time
from rpi_ws281x import *
LED_COUNT = 14 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
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
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()
while True:
print ('Running display')
for j in range(100):
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(50, 50, 50))
strip.show()
time.sleep(.05)
Yes, those nested loops are necessary. Simplifying to something like this without loops doesn't turn on any LEDs at all:
strip.setPixelColor(0, Color(100, 100, 100))
strip.show()
time.sleep(10)
Demo Video
When I run that code (the first block), this is what happens: https://youtu.be/nzMCeyBNY50
Every time I run the code, I wait a few seconds, and eventually some LEDs turn on. It's different every time: sometimes a couple turn on, sometimes all of them, sometimes they turn off again for a little bit as it keeps running, etc. This was true even before I switched to using the Logic Level converter from the second tutorial, and happens the same way even if I run the original strandtest.py
.
Parts
I've followed this schematic from the second tutorial linked above. Note that I'm powering 14 LEDs currently (but would like to do the full strip in the future). Also, this schematic shows the power for the LEDs running through the breadboard, but I've soldered the red power+ directly instead.
Here's a list of the parts I used:
- Raspberry Pi 3 B+ (already owned)
- Breadboard, miscellaneous wires, and solder (already owned)
- Logic Level converter
- WS2812b RGB LED strip (5 meters, 30/m)
- 5V 10A Power Supply