🛠 Piloter la LED RGB embarquée WS2812 d'une carte RP2040 générique

RP2040 (generic board / chip) · debutant · Schéma : IMG-rp2040-generic-debutant-1-rp2040-neopixel-ws2812.svg — carte RP2040 générique type Waveshare Zero avec sa LED WS2812 sur GP16 mise en évidence, câble USB-C branché, puce PIO représentée générant le signal

Objectives

"Generic" RP2040 boards (Waveshare RP2040 Zero, Adafruit Feather/QT Py RP2040, SparkFun Micro RP2040…) often do not have a simple LED like the Pico: they feature an addressable WS2812 ("NeoPixel") LED driven by a single-wire 800 kHz protocol that MicroPython generates via the RP2040's PIO. By the end of this tutorial, you will be able to find the LED pin on YOUR board and set it to any color.

Hardware

Complete code

# main.py — LED WS2812 embarquée (GP16 Waveshare Zero, GP17 Feather)
import neopixel
from machine import Pin
import time

PIN = 16                      # à adapter à ta carte !
led = neopixel.NeoPixel(Pin(PIN), 1)   # chaîne d'une seule LED

for r, g, b in [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 64, 0)]:
    led[0] = (r, g, b)        # tuple (R, G, B) 0..255
    led.write               # la PIO envoie la trame, le CPU est libre
    time.sleep_ms(500)

while True:                   # « arc-en-ciel » rapide
    for i in range(256):
        led[0] = (i, 255 - i, 128)
        led.write
        time.sleep_ms(5)

Expected verification

The LED turns red, green, blue, and orange at 500 ms intervals, then displays a continuous gradient. Unlike a standard LED, nothing blinks "off" between two colors: the LED retains its last frame, because the WS2812 stores its command. If your board has multiple WS2812 LEDs (some badges, QT Py with strobe), pass the actual length to NeoPixel(..., n).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials