Usage of GPIO 10 (SPI) to drive Nanopixel LEDs

Hi !

I’m currently struggling to get my vu-meter Nepixel LEDs to turn on.

They are hooked to gpio 10 (SPI) and my Python code looks like this (ChatGPT wrote it but it’s basically the same as in the adafruit docs):


import board
import neopixel

# Configuration des LEDs
LED_COUNT = 64        # Nombre total de LEDs
LED_PIN = board.D10   # GPIO utilisé pour le signal de données (GPIO 10)
BRIGHTNESS = 0.5      # Luminosité (entre 0.0 et 1.0)

# Initialisation de la bande LED
pixels = neopixel.NeoPixel(
    LED_PIN, LED_COUNT, brightness=BRIGHTNESS, auto_write=False
)

# Fonction pour allumer toutes les LEDs en blanc
def allumer_leds_en_blanc():
    pixels.fill((255, 255, 255))  # Blanc (R, G, B)
    pixels.show()

# Fonction pour éteindre toutes les LEDs
def eteindre_leds():
    pixels.fill((0, 0, 0))  # Éteint (R, G, B)
    pixels.show()

# Fonction pour créer un dégradé de couleur
def degrader():
    for i in range(LED_COUNT):
        pixels[i] = (i * 4 % 255, (255 - i * 4) % 255, i * 2 % 255)
    pixels.show()

# Boucle principale
if __name__ == "__main__":
    try:
        print("Allumage des LEDs en blanc")
        allumer_leds_en_blanc()
        
        input("Appuyez sur Entrée pour créer un dégradé...")
        degrader()
        
        input("Appuyez sur Entrée pour éteindre les LEDs...")
        eteindre_leds()
        
    except KeyboardInterrupt:
        print("Extinction des LEDs...")
        eteindre_leds()

I get an SPI initialisation error.
Sadly I have already committed to gpio 10 on my pi+teensy MIDI controller custom PCB so I pretty much have to use it or else I will not have my leds on.

I have seen that you guys restricted SPI use for the elk pi hat, but since it is discontinued it does not make sense on my setup to have it forcefully disabled by elk.

Is there any way I can enable SPI back ?
It is basically the one last thing keeping me from finishing this project.
I am having so much fun and I feel proud about the progress so far !
I’ll post about it when I’m done, and it’s open source so anyone can build one !

Cheers
Leo

Hi,
have you enabled SPI from the config.txt?

You need to set this

## spi
##     Set to "on" to enable the spi interfaces
dtparam=spi=on

Hope it helps,
Marco

1 Like

Hi Marco, thank you very much for your swift response !

My /boot/config.txt currently contains the following :

dtparam=spi=on
dtoverlay=spi0-1cs

So now that I try again I see that I do not have any SPI-related error, but now the Blinka library tells me this :
RuntimeError: Not running on a RPi!

So I guess that fixed it and the error is not related to ELK OS anymore !

Thank you so much !