I recently bought a 1 meter WS2812B strip. I installed the Adafruit Neopixel Circuit python library with the following commands:
sudo pip3 install --upgrade setuptools
pip3 install RPI.GPIO
pip3 install adfafruit-blinka
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
I then created a python file, test.py
with the following content:
import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 144)
for i in range(0, 144):
pixels[i] = (255, 0, 0)
I ran this using sudo python3 test.py
, and the strand lit up in an assortment of colors, and was flickering. I tried running the script again, and obeserved the same behavior - the colors were different, but not the ones I specified. Because the strip is GRB, I tried replacing the third line with this:
pixels = neopixel.NeoPixel(board.D18, 144, pixel_order=neopixel.GRB)
I ran the script again, but to no avail. The same behavior occurred. I then tried removing the loop, and simply setting pixel 0 to be red:
pixels[0] = (255, 0, 0)
The pixel was still displaying a random color (different color each time I run the script).
I then tried to switch GPIO pins to Pin 13, but got the following error while doing so:
RuntimeError: ws2811_init failed with code -11 (Selected GPIO not possible)
Any ideas on how to get this to work? Or did I buy faulty LEDs?
EDIT: Fixed thanks to mrSidX. I needed to add a ground connection to the Raspberry Pi. The below image contains the final wiring needed. The wires coming from the left are from an external PSU, and the wires going to the right are going to the strip (red = 5v, black = ground, blue = data).
The final code was this:
import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 144, pixel_order=neopixel.GRB)
pixels[0] = (255, 0, 0)