ESP8266 & WS2812

ESP8266 & WS2812

I managed to get the ESP and the WS2812 individually configurable LEDs to play nice to each other and coded the ESP through the Arduino IDE. The final setup which I used, I thought I had tried before but somehow I didn’t apparently. So what worked for me is the following technical setup:

A 5V to 3.3V converter with a USB feed to my laptop, +5V to +5V and GND to GND. Next connect the 3.3V of the converter to 5V of the WS2812 and GND of the 3.3V end to the GND of the WS2812 led strip (or circle in my case) and connect the same GND to the GND of your ESP. I have it now working with a NodeMCU v1 and a Wemos D1 Mini. The DI pin (data in) of the WS2812 goes to pin D4 which is GPIO2.

For the library you need the Adafruit Neopixel library which you can download here. The example code should work (check to make sure you select the right pin).

github-mark-32px Available on GitHub with more comment in the code. Direct download.

You can also try my example which is a running yellow strip of light:

//
// The library from Adafruit which enables the use of the WS2812
// or NeoPixel
//
#include <Adafruit_NeoPixel.h>

//
// The pin the circle of WS2812 leds is connected to
//
#define CIRCLEPIN 2
//
// The number of leds in our circle
//
#define PIXELCOUNT 12

//
// Initialize the Adafruit library
//
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXELCOUNT,CIRCLEPIN,
  NEO_GRB+NEO_KHZ800);

//
// The number of leds lit
//
byte maxLed = 1;
//
// Is the number of leds increasing or decreasing
//
int direction = 1;

void setup() {
  //
  // Start the led string and turn them all off
  //
  pixels.begin();
  for(byte i=0;i<PIXELCOUNT;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
  }
  pixels.show();
}

void loop() {
  //
  // Turn the first 'maxLed' leds yellow
  //
  for(byte i=0;i<maxLed;i++){
    pixels.setPixelColor(i, pixels.Color(55,42,0));
  }
  //
  // Set the remaining leds black
  //
  for(byte i=maxLed;i<PIXELCOUNT;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
  }
  //
  // Don't forget to call the pixels.show();
  //
  pixels.show();
  delay(100);
  //
  // Determine the next step in number of leds to show
  //
  maxLed = maxLed+direction;
  if (maxLed<1 || maxLed>PIXELCOUNT) {
    direction = -direction;
    maxLed = maxLed+direction;
  }
}

A very basic example but I was very happy that it worked.

Theoratically speaking, you should be able to run this from other pins and with a small number of leds, maybe even without a seperate power source. I also still want to try to run it at 5v and use a logical converter for the DI pin. If I manage to do this, I will share this.

One thought on “ESP8266 & WS2812

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s