Monday, May 25, 2020

Exploring WLED firmware for NeoPixel LED control

Continuing from the foray into RGB LEDs with the MRR ESPx boards, I decided to see if I can find something to control RGB LEDs via WiFi. And came across this firmware called WLED.

It actually works great with ESP8266 and ESP32 microcontrollers. I have successfully flashed it to a Wemos D1 Mini (which is ESP8266-based) and a Wemos Lolin32 OLED (which is ESP32 development board with OLED display). Both of them work with a small strip of 10 NeoPixel LEDs. It seems that WLED can also be used to control those "analog" RGB LEDs too. To do that, you will need to change some of the #define statements in NpbWrapper.h. The pin used for the data pin (defaults to GPIO2) of NeoPixel (WS2818B) strips can also be changed in NpbWrapper.h. If you do not have an IR receiver, you can disable IR by defining the pin to -1 (default value is 4). Other settings are found in wled.h.

I am, however, facing some trouble getting OLED support to work. Such features are supposed to be easily added via the usermod.cpp file, with examples here. I tried to use this usermod, and set the constructor to
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(U8X8_PIN_SCL, U8X8_PIN_SDA, U8X8_PIN_NONE);
but that did not work for me. Tried HW_I2C too, but still no joy. BTW, the SCL pin is 5 and SDA pin is 4 on the Wemos Lolin32 OLED, and I even disable the IR pin to make sure there is no conflict.

Still, even without the OLED display, NeoPixel control works. And there is no issue with the first pixel being of a different color, which is an issue when using the Adafruit_NeoPixel library (see comment in this post). The web UI looks great too, with many interesting presets, patterns and palettes.

As for which development board to use, I think the best one would be a development board with a small and thin footprint that can be powered by USB, with the 5V, GND, and at least GPIO2 broken out for connection to the NeoPixel strip. You can probably even design one. It just needs a ESP8266 or ESP32 microcontroller, the CP2102 or CH340 USB-to-serial chip, a few transistors to help with the flashing circuit, a 3.3V voltage regulator, and a USB connector. Plus a few passive components like resistors and capacitors. Probably two ESD protection diodes. And the pin header for pins to expose. But this is another PCB design project for another day...

Update: I managed to get the OLED display working by using pin 4 for SCL and pin 5 for SDA... this seems to be the right pins to use instead of the other way round... 😅😂

Update 2: The video below gives an introduction on how to flash WLED firmware to an ESP8266. A similar process can be used for ESP32. The process is toward the end of the video.

For information on what the various settings are, this is a great video.
 

No comments: