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). This image

The final code was this:

import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 144, pixel_order=neopixel.GRB)
pixels[0] = (255, 0, 0)

There are two ground wires. One with the neopixel strands main power, and another coupled with the signal wire. Try grounding the signal coupled ground to the controller's ground.

Your instructions are seemingly on the right track, one other thing to keep in mind is the Neopixels strips come with essentially 4 wires.

Ground, Main Power and the signal wire, with a smaller ground wire.

This smaller ground wire can make it discolored from out of sync signaling with what the controller is telling it. Try to ground this to the controller ground and not the Neo Pixel Power coupled ground.

Double check your neopixel.GRB constant is correct, which you might have already set correctly.

Ensure you have sufficient power or its own power supply to the neopixel strips power circuit. Then the signal wire and it's couple ground should be able to connect directly to the controller.

Hope this helps.

  • 1
    This solved the issue, thanks! Updated question with my final wiring and code. – Ryan Z Jan 1 at 19:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.