FastLED 3.9.15
Loading...
Searching...
No Matches
Esp8266Uart Directory Reference
+ Directory dependency graph for Esp8266Uart:

Files

 Esp8266Uart.ino
 

Detailed Description

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.

Overview

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.

How It Works

The driver encodes WS2812 LED data into a UART byte stream at 3.2 Mbps:

Usage

Enable the UART driver

Option 1: Define before including FastLED

#define FASTLED_ESP8266_UART
#include <FastLED.h>
void setup() {
FastLED.addLeds<UARTController_ESP8266<GRB>>(leds, NUM_LEDS);
}
void setup()
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::CRGB CRGB
Definition crgb.h:25

Option 2: Explicit controller type

#include <FastLED.h>
void setup() {
FastLED.addLeds<UARTController_ESP8266<GRB>>(leds, NUM_LEDS);
}

Advantages

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

Trade-offs

⚠️ 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

Pin Assignment

Configuration

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)
CLEDController * controller

Performance

When to Use This Driver

Use the UART driver when:

Stick with the default bit-bang driver when:

Credits

This implementation is based on the proven technique from the NeoPixelBus library, adapted to work seamlessly with FastLED's API and features.