examples/Esp8266Uart/README.md
This example demonstrates the opt-in UART-based WS2812 driver for ESP8266, which provides improved stability under Wi-Fi load compared to the default bit-bang driver.
The ESP8266's single-core architecture and frequent NMI/RTOS interrupts can disrupt bit-bang timing loops, especially when Wi-Fi is active. This UART driver solves this problem by using the hardware UART1 peripheral to generate precise LED timing automatically.
The driver encodes WS2812 LED data into a UART byte stream at 3.2 Mbps:
1000 (0.35 µs high, 0.8 µs low)1100 (0.7 µs high, 0.6 µs low)Option 1: Define before including FastLED
#define FASTLED_ESP8266_UART
#include <FastLED.h>
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<UARTController_ESP8266<GRB>>(leds, NUM_LEDS);
}
Option 2: Explicit controller type
#include <FastLED.h>
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<UARTController_ESP8266<GRB>>(leds, NUM_LEDS);
}
✅ Hardware timing - UART peripheral shifts bits automatically ✅ Minimal CPU overhead - Main loop remains responsive ✅ Wi-Fi stable - No NMI interrupt timing issues ✅ Precise timing - Maintains ±150ns WS2812 tolerance
⚠️ Higher RAM usage - ~12 bytes per LED (300 LEDs = 3.6 KB buffer) ⚠️ Single pin only - GPIO2 (UART1 TX-only on ESP8266) ⚠️ No parallel output - Not compatible with multi-strip modes
You can optionally configure the baud rate and reset time:
UARTController_ESP8266<GRB> controller;
controller.setBaud(3200000); // Default: 3.2 Mbps
controller.setResetTimeUs(300); // Default: 300 µs (WS2812 requires >= 50 µs)
FastLED.addLeds(&controller, leds, NUM_LEDS);
Use the UART driver when:
Stick with the default bit-bang driver when:
This implementation is based on the proven technique from the NeoPixelBus library, adapted to work seamlessly with FastLED's API and features.