🛠 Bandeau NeoPixel piloté par le périphérique RMT
Objectives
Move from a single pixel to an addressable strip by understanding the hardware layer: on the ESP32-S3, the Adafruit NeoPixel library generates WS2812 frames (800 kHz) using the RMT (Remote Control) peripheral, a DMA-driven pulse generator. You will write a "sweep" animation on 8 pixels, size the power supply (a pure white WS2812 draws up to 60 mA), and avoid frame corruption caused by Wi-Fi interrupts.
Hardware
- 1 ESP32-S3 board (GPIO48 free of any onboard pixel, or external strip)
- 1 8-pixel WS2812B strip (5 V)
- 1 330 to 470 ohm resistor for the DATA line
- Dedicated 5 V power supply or USB port capable of providing 500 mA
- Wires: DATA -> GPIO48 via resistor, VCC -> 5 V, GND -> common GND
Complete Code
// Bandeau 8x WS2812 sur GPIO48, trames generees par le peripherique RMT
#include <Adafruit_NeoPixel.h>
#define PIN 48
#define N 8
Adafruit_NeoPixel strip(N, PIN, NEO_GRB + NEO_KHZ800);
uint32_t couleur(uint8_t r, uint8_t g, uint8_t b) {
return strip.Color(r, g, b);
}
void setup {
strip.begin;
strip.setBrightness(60);
strip.show; // eteint tout au demarrage
}
void loop {
static uint8_t pos = 0;
static int8_t dir = 1;
strip.clear;
strip.setPixelColor(pos, couleur(255, 80, 0)); // tete
if (pos > 0) strip.setPixelColor(pos - 1, couleur(90, 30, 0));
if (pos < N - 1) strip.setPixelColor(pos + 1, couleur(90, 30, 0));
strip.show;
if (pos == 0) dir = 1; else if (pos == N - 1) dir = -1;
pos += dir;
delay(60);
}
Expected Verification
An orange dot sweeps back and forth across the strip with a fading trail. The 8 pixels respond uniformly, without any erratic green pixels. By opening the serial monitor, you can display ESP.getFreeHeap to verify that the internal RAM (512 KB) remains comfortable: the library allocates a copy of the pixel buffer and configures an RMT channel.
Common Errors
- Insufficient power: powering 8 pixels at full white via only the board's 3.3 V pin causes voltage drops and triggers resets; use the strip's 5 V supply and a common ground.
- Forgetting the series resistor on DATA: it often "works," but frames are sensitive to noise on long ribbon cables; the 330-470 ohm resistor is cheap insurance.
- Swapping DATA and the strip's output signal: the input connector is marked with a DATA IN arrow, not DATA OUT.
- Corruption with active Wi-Fi: radio interrupts can shift RMT pulses; the library uses DMA, but in case of flickering, lower the brightness and avoid allocations inside loops.
- Wrong color order: NEO_GRB is the standard wiring for WS2812B; an SK6812 RGBW strip requires NEO_GRB + NEO_KHZ800 with W channel handling.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino