adafruit / Adafruit_CircuitPython_NeoPixel_SPI

SPI driven CircuitPython driver for neopixels.
MIT License
24 stars 11 forks source link

Neopixel with SPI on Raspberry Pi OS (5.4.79) #25

Closed Redrocirt closed 3 years ago

Redrocirt commented 3 years ago

Hello there, I'm trying to use SPI to control some Neopixels but I am getting only some strange results. For example the Neopixels light up bright white instead of the given color.

Can someone please test if this SPI driver is still working with an up-to-date Raspberry Pi OS?

Here's my setup:

Raspberry Pi Zero W with up-to-date Raspberry Pi OS: Linux raspberrypi 5.4.79+ #1373 Mon Nov 23 13:18:15 GMT 2020 armv6l GNU/Linux

SPI is enabled

Neopixel "DIN" is connected to Pin 19 = GPIO 10

Installed packages:

sudo pip3 install adafruit-blinka
sudo pip3 install adafruit-circuitpython-neopixel-spi

Test with RGB Neopixels (Adafruit 4356)

A simple test setup with only 4 connected neopixels. My simple test script:

import time
import board
import neopixel_spi as neopixel

NUM_PIXELS = 4
PIXEL_ORDER = neopixel.GRB
DELAY = 1

spi = board.SPI()

pixels = neopixel.NeoPixel_SPI(
    spi, NUM_PIXELS, brightness=0.1, auto_write=False, pixel_order=PIXEL_ORDER
)

print("All neopixels OFF")
pixels.fill((0,0,0))
pixels.show()
time.sleep(DELAY)

print("One neopixel red")
pixels[0] = (10,0,0)
pixels.show()
time.sleep(DELAY)

print("All neopixels green")
pixels.fill((0,10,0))
pixels.show()
time.sleep(DELAY)

print("All neopixels OFF")
pixels.fill((0,0,0))
pixels.show()
time.sleep(DELAY)

print("End of test")

The results are different with every call of the script. For example:

First call: All off - one red - ALL WHITE - all off Second call: ALL WHITE - one red - ALL WHITE - don' go off, stay bright white Third call: ALL WHITE - all off - one green - ALL WHITE - all off

Looks like there is something wrong in the shift register or bit/byte arrangement of the driver?

I tested different variations of my script with different colors. The neopixels often only light up bright white and sometimes they also do not turn off whenfill((0,0,0)) is called.

In another test series I changed the script to RGBW (with 4 digit color declarations like fill((10,0,0,0)) ) and connected 4 RGBW neopixels (Adafruit 4776) instead of RGB. Same weird results, often only bright white instead of the defined color...

Thanks for your support, happy holidays and stay safe and healthy

Redrocirt commented 3 years ago

I think I figured out how to solve this (at least when the neopixels are connected to SPI0/GPIO10):

Simply change bit0 from 0b11000000 to 0b10000000:

pixels = neopixel.NeoPixel_SPI(
    spi, NUM_PIXELS, brightness=0.1, auto_write=False, pixel_order=PIXEL_ORDER, bit0=0b10000000
)

This seem to be working with both neopixel variants (RGB = Adafruit 4365 and RGBW = Adafruit 4776)