🛠 Bandeau NeoPixel piloté par le périphérique RMT

ESP32-S3 · intermediaire · Schéma : IMG-esp32-s3-intermediaire-1-esp32-s3-neopixel-rmt.svg — Bandeau de 8 pixels WS2812 alimenté en 5 V via le bus USB, données reliées à GPIO48 par une résistance de 330 ohm, masse commune avec la carte ESP32-S3.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials