adafruit / Adafruit_CircuitPython_NeoPixel

CircuitPython drivers for neopixels.
MIT License
302 stars 98 forks source link

Code breaks when using only 2 leds #142

Open ShadowGamer3 opened 1 year ago

ShadowGamer3 commented 1 year ago

Hi, idk if this is happening because its a niche use-case, but I have a project for my job where I'm trying to initialize a "strip" of only two ws2812b LEDs and make them blink red and green. I've been following this guide (which uses this library) to do so: https://core-electronics.com.au/guides/raspberry-pi/fully-addressable-rgb-raspberry-pi/

The problem I'm having is that whenever I try to control the LEDs, they behave unpredictably, and im unable to get the colors I want to appear. Instead when I run the script, the LEDs stay dark for between 30-45 seconds (the timing is different each run, I've timed it), then they each appear as a random color. On one execution, they may appear orange/blue, another magenta/yellow, there was even one time only one LED came on at a time, so I have no clue what's happening here.

I verified that it wasn't my code that was the issue by essentially copy/pasting the code in the guide, but accounting for only 2 leds, but got the random behavior described above. I was able to get that same code to work once before on an older system, but after updating python on my pi (from python2, it was an older version of raspbian and presumably the library too) everything broke and ive been unable to revert back. Now that older system can't even see the neopixel module.

Since then, I've flashed another sd card with a fresh install of the latest version of raspbian (twice) and followed the linked guide to the letter, but now i'm back to getting that random behavior again. I've also tried installing the same packages on the same version of raspbian that I got it to work with before, but pip keeps throwing syntax errors when i try to install the package, when it just did on the newer OS.

Now I'm starting to rub against my deadline for this project and I've exhausted the solutions I can think of on my own. Can I please get some assistance with this issue?

This is the code im using:

import neopixel
from time import sleep
import board

strip = neopixel.NeoPixel(board.D18, 2)

while True:
            strip[0] = (0, 204, 0)
            strip[1] = (204, 0, 0)

            sleep(.1)

            strip[0] = (0, 0, 0)
            strip[1] = (0, 0, 0)

            sleep(1)