🛠 OctoWS2811 : piloter 8 rubans WS2812 en parallèle par DMA (presque zéro CPU)
Objectives
Understand why the Teensy 3.2 is the queen of LED walls: the OctoWS2811 library drives 8 WS2811/WS2812 strips in parallel via DMA — up to 8800 LEDs refreshed at 30 Hz, ~4000 LEDs recommended per Teensy 3.2, 1000 LEDs updated in 3.8 ms (theoretically 240 Hz) — with almost zero CPU usage: show returns in 2 µs. You will wire 8 strips (or just one to start) with the essential 74HCT245 buffer, then look at WS2812Serial and SmartMatrix alternatives.
Hardware
- 1 Teensy 3.2
- 8 WS2812 strips (fixed pins on Teensy 3.2: 22, 14, 7, 8, 6, 20, 21, 5) — to start, 1 single strip on pin 22 works
- 1 74HCT245 buffer (e.g., OctoWS2811 Adaptor PJRC) — mandatory: recent WS2812B strips require a HIGH level of approximately 0.7×VDD; the Teensy's 3.3 V output is unreliable when connected directly
- Properly sized 5 V power supply (3 strips of 64 LEDs at full white ≈ 30 A peak!) — ATX power supply spikes on the 5 V line have already destroyed boards (OctoWS2811 page)
- Electrolytic capacitor (e.g., 1000 µF) near the first pixel of each strip
Complete Code
API verified on the official OctoWS2811 page:
#include <OctoWS2811.h>
// 8 rubans de 256 WS2812B sur les broches 22,14,7,8,6,20,21,5 (fixes)
const int ledsPerStrip = 256;
DMAMEM int displayMemory[ledsPerStrip * 6]; // double buffer DMA (6 int/LED)
int drawingMemory[ledsPerStrip * 6]; // back buffer que votre code dessine
const int config = WS2811_GRB | WS2811_800kHz; // ordre des couleurs + debit
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
void setup {
leds.begin;
leds.show; // efface toutes les LED
}
void loop {
while (leds.busy) { } // attend la fin du transfert DMA precedent
for (int i = 0; i < ledsPerStrip * 8; i++) {
leds.setPixel(i, 120, 0, 0); // rouge ; setPixel(num, r, g, b)
}
leds.show; // lance la MAJ DMA, revient en ~2 us
// Le CPU est libre ici : 1000 LED prennent 3,8 ms au total
delay(16);
}
Expected Verification
The 8 strips light up in red synchronously. Measure the CPU usage: it is marginal — the WS2812 signal synthesis is done by the DMA, not by your loop. The while (leds.busy) { } prevents overwriting a buffer during a transfer. For a complete video wall, the VideoDisplay example in the library streams PC video to multi-Teensy networks with frame synchronization (1920 LEDs shown on two boards in the PJRC demo, scalable to several thousand).
Alternatives Depending on the Project
- WS2812Serial (GitHub PaulStoffregen): up to 5 non-blocking DMA instances on hardware serial ports — when the 8 OctoWS2811 pins are already taken.
- SmartMatrix + SmartLED Shield v4 (Pixelmatix): direct driving of HUB75 RGB panels from 32x16 to 64x64, GIF playback, FastLED integration.
Common Errors
- Powering the strips via the board's 3.3 V or USB 5 V: a PC's USB provides ~500 mA, while a strip at full white draws tens of amperes — a dedicated 5 V power supply is mandatory, with grounds connected.
- Skipping the 74HCT245: pixels flicker or stay off with recent strips (insufficient HIGH level at 3.3 V).
- Spikes from a poorly filtered ATX power supply: documented board destruction — place a capacitor at the head of the strip, use short and thick 5 V cables.
- Forgetting DMAMEM on displayMemory: the DMA cannot read any RAM area — the variable must be in DMA memory.
- Writing to drawingMemory during a transfer without waiting for busy: torn images.
- Confusing color order: WS2811_GRB vs WS2811_RGB — blue LEDs appearing instead of red come from this, not from reversed wiring.
Other tutorials for this board
- Premiers pas sur la Teensy 3.2 : Teensyduino, HalfKay et premier Blink
- Broches, ADC 13 bits, DAC 12 bits et PWM : dompter les E/S de la Teensy 3.2
- Un instrument MIDI USB en 10 minutes : Bounce, boutons et règle d'or du drain
- Audio Shield SGTL5000 : boucle stéréo 44,1 kHz et outil de conception graphique
- Timers matériels, interruptions imbriquées et FASTRUN : la vitesse Cortex-M4
- Intégration produit : alimentation VIN/VUSB, régulateur 250 mA, RTC à quartz et EEPROM
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino