Published: Mar 02, 2023

ESP8266 - WS2815 LED Strip

Introduction

The WS2815 is a cost-effective RGB LED suitable for a wide variety of applications in consumer electronics or lighting. Some key features are:

  • 12V power supply to reduce voltage drop for long distances
  • Backup data line (DIN, BIN) so the strip still works with single defective LEDs

The ESP8266 is a SoC with Wi-Fi capability and a good price/performance ratio and perfect for simple IoT or home automation tasks that don’t require bluetooth. For more power, bluetooth and a bunch of other features have a look at the ESP32 which has quickly become one of my favorite SoCs for many projects.

Schematic

Since the ESP8266 (and ESP32) use 3.3V logic and the LED strip requires 5V logic it is strongly recommended to use a level shifter. I used the SN74AHCT125N but there are many other options, just avoid those based on BJTs since they are often too slow due to saturation.

The SN74AHCT125N passes data from A to Y when the respective OE input is connected to GND.

Project Setup

The goal here is to get it up and running as quickly as possible. To achieve this I recommend using platformio. Plugins for VSCode and CLion are available. Once installed the pio command should be available.

Now you need to find the ID of your board for platformio. One way is to use the boards command like so:

pio boards nodemcu
Platform: espressif8266
=============================================================================
ID         MCU      Frequency    Flash    RAM    Name
---------  -------  -----------  -------  -----  ----------------------------
nodemcu    ESP8266  80MHz        4MB      80KB   NodeMCU 0.9 (ESP-12 Module)
nodemcuv2  ESP8266  80MHz        4MB      80KB   NodeMCU 1.0 (ESP-12E Module)

I have a NodeMCU 1.0 so I am going to use nodemcuv2 for the board ID. To initialize a new project for this board use:

pio project init --board nodemcuv2

This will generate following file along with a basic folder structure:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino

The arduino framework is fine for simple applications, for more complex applications I prefer to use a RTOS like FreeRTOS due to features like SMP, memory protection, runtime stats and tracing.

Code

To control the LEDs I will use the Adafruit NeoPixel library. It has a small memory footprint, good performance and is easy to use. Another great library is FastLED which includes more functions and has better timing stability.

To add the dependency add following line to your platformio.ini:

lib_deps = adafruit/Adafruit NeoPixel@^1.11.0

Now build the project to trigger downloading the library:

pio run

You can also run pio home, add your project and manage your dependencies in a web based GUI.

Now write following code to test the LED strip:

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(61, D2, NEO_GRB + NEO_KHZ800);

void setup() {
    pinMode(D2, OUTPUT);

    strip.begin();
    strip.setBrightness(255);
    strip.show();
}

void loop() {
    for (int i = 0; i < strip.numPixels(); i++) {
        strip.clear();
        strip.setPixelColor(i, Adafruit_NeoPixel::Color(255, 255, 255));
        strip.show();
        delay(50);
    }
}

To build and upload run:

pio run -t upload

If everything is working you should see each LED in your strip light up white one after another.

Troubleshooting

Ideally you have access to an oscilloscope to check the signals and voltage levels since, but here are some common errors and solutions I encountered. Overall the WS2815 seem quite tolerant when it comes to the 12V supply and the timing stability of the data.

LED strip not lighting up at all

  • 12V power supply can not supply enough current
  • GND of LED strip not connected to ESP8266 GND
  • Mislabeled pins on the ESP8266 board

LED strip flashing/resetting

  • 12V power supply can not supply enough current
  • 5V supply is of poor quality, try to add a small capacitor to filter noise and a larger one to smooth out the power delivery.

Failed to connect to ESP8266: Timed out waiting for packet header

  • Make sure drivers (CP210x USB to UART) are installed and working
  • Check the COM port used for uploading
  • Some boards require you to manually hold down a button like “FLASH” when uploading
  • Try another cable or reducing the upload baud rate using the upload_speed setting