lattepanda-sigma2-rp2350-ws2812b-rgb-10.ino

LattePanda Sigma 2: Intel Core Ultra X7 358H Single-Board Server · File : lattepanda-sigma2-rp2350-ws2812b-rgb-10.ino · Language : micropython · Use case : Piloter une bande de LEDs adressables WS2812B via le microcontrôleur RP2350 pour un affichage visuel d'état système.

MicroPython script using 'machine' and 'neopixel' libraries to control WS2812B LEDs connected to the RP2350 GPIO header. Ideal for visualizing CPU load or network alerts.

Connect the DATA pin of a WS2812B strip to a free GPIO on the RP2350 header (e.g., GP15), VCC to 3.3V, and GND to ground. If the LED strip draws more than 500mA, power it separately to avoid damaging the RP2350. Upload this script to the RP2350 via Thonny or serial, then run it. Check the official LattePanda schematic for exact physical pin mapping.

lattepanda-sigma2-rp2350-ws2812b-rgb-10.ino

from machine import Pin
import neopixel
import time
import math

# Configuration du hardware
# Sur LattePanda Sigma 2, le RP2350 expose des broches GPIO via un connecteur.
# Supposons que la broche physique connectée au DATA de la bande LED soit GP15 (à vérifier selon votre schéma câblage).
PIN_LED = 15
NUM_LEDS = 8  # Nombre de LEDs sur la bande

# Initialisation de la bande LED
np = neopixel.NeoPixel(Pin(PIN_LED), NUM_LEDS)

def set_color(r, g, b):
    for i in range(NUM_LEDS):
        np[i] = (r, g, b)
    np.write()
    time.sleep(0.1)

def rainbow_cycle(wait):
    for j in range(255):
        for i in range(NUM_LEDS):
            pix_index = (i * 255 // NUM_LEDS + j) & 255
            np[i] = colorwheel(pix_index)
        np.write()
        time.sleep(wait)

def colorwheel(pos):
    if pos < 0 or pos > 255:
        return (0, 0, 0)
    if pos < 85:
        return (255 - pos * 3, pos * 3, 0)
    if pos < 170:
        pos -= 85
        return (0, 255 - pos * 3, pos * 3)
    pos -= 170
    return (pos * 3, 0, 255 - pos * 3)

print("Démarrage de la démo RGB sur RP2350...")

# Séquence de test
try:
    # 1. Allumer tout en rouge
    set_color(255, 0, 0)
    time.sleep(0.5)
    
    # 2. Allumer tout en vert
    set_color(0, 255, 0)
    time.sleep(0.5)
    
    # 3. Allumer tout en bleu
    set_color(0, 0, 255)
    time.sleep(0.5)
    
    # 4. Effet arc-en-ciel
    rainbow_cycle(0.01)
    
    # 5. Effet progressif (simulation de charge CPU)
    for i in range(NUM_LEDS + 1):
        np.clear()
        for j in range(i):
            # Vert pour faible charge, rouge pour haute
            intensity = int(255 * (j / NUM_LEDS))
            np[j] = (intensity, 255 - intensity, 0)
        np.write()
        time.sleep(0.1)
        
    # Extinction propre
    np.fill(0)
    np.write()
    print("Terminé.")

except KeyboardInterrupt:
    np.fill(0)
    np.write()
    print("Interruption manuelle.")

← Back to the board