driving a RGB LED (WS2812) on an esp32-s2-saola-1

RobLatour
Posts: 9
Joined: Mon Dec 30, 2019 4:23 am

driving a RGB LED (WS2812) on an esp32-s2-saola-1

Postby RobLatour » Fri Jul 24, 2020 10:05 pm

I have an esp32-s2-saola-1 which has an addressable RGB LED (WS2812), driven by GPIO18 as described here:
https://docs.espressif.com/projects/esp ... -v1.2.html

Problem is I haven't yet found an Arduino compatible library to drive the RGB led correctly.

As an example, using FastLED ( http://fastled.io/ ) the code below turns the led green (when it should turn it red) and then generates the following error:

Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0)

and then reboots.

I suspect the led may be a GRB device, and not a RGB device as advertised, but that's not as much of a concern as the reboot.


#define LED_PIN 18
#define NUM_LEDS 1
#define BRIGHTNESS 10
#define LED_TYPE WS2812
#define FASTLED_ALLOW_INTERRUPTS 0

#include "FastLED.h"

CRGB leds[NUM_LEDS];

void setup()
{

Serial.begin(115200);
Serial.println("Starting");
delay(5000); // saftey delay
Serial.println("Started");

FastLED.addLeds<WS2812, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS );

}

void loop() {

Serial.println("Red");
leds[0] = CRGB::Red;
FastLED.show(); // << failes here; have also tried FastLED.delay(100); as well as following FastLED.show(); with yield();
delay(1000);

Serial.println("Green");
leds[0] = CRGB::Green;
FastLED.show();
delay(1000);

Serial.println("Blue");
leds[0] = CRGB::Blue;
FastLED.show();
delay(1000);

}

A bunch of research and trials has me thinking the problem is tied to the esp32-s2-saola-1 being based on a single core chip, but I cannot confirm.

Would appreciate either:
a) knowing if I am missing something above
or
b) know another Arduion compatible library that allows the LED to be driven correctly.

With thanks

savage
Posts: 8
Joined: Mon Jul 15, 2019 9:24 pm

Re: driving a RGB LED (WS2812) on an esp32-s2-saola-1

Postby savage » Sat Jul 25, 2020 5:46 am

FastLED does not look like it has been updated for ESP32-S2, with a lot of allowed pin assignments and hardware capabilities hard-coded to the original ESP32. For example, the default clockless driver uses 8 RMT channels, though the ESP32-S2 has only 4 RMT channels.

The core panic error means necessary task switching interrupts (to deal with WiFi tasks, for example) are not being processed in a timely manner: try removing the FASTLED_ALLOW_INTERRUPTS line. With the default RMT driver, I think FastLED should be able to drive the WS2812 lines even while the chip deals with other processes (WiFi).

If that doesn't work, looking at the ESP32 header files in FastLED, specifically the clockless RMT driver, gives some suggestions for altering the driver behavior. Try adding some of the following define statements (one at a time) before including FastLED.h:

Code: Select all

#define FASTLED_RMT_MAX_CHANNELS 1
#define FASTLED_RMT_BUILTIN_DRIVER 1
#define FASTLED_INTERRUPT_RETRY_COUNT 1
For red appearing as green, you can try using GRB instead of RGB in the initialization line to see if it just a color ordering issue:

Code: Select all

FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

RobLatour
Posts: 9
Joined: Mon Dec 30, 2019 4:23 am

Re: driving a RGB LED (WS2812) on an esp32-s2-saola-1

Postby RobLatour » Sat Jul 25, 2020 12:56 pm

Thank you, but adding:

Code: Select all

#define FASTLED_RMT_MAX_CHANNELS 1
#define FASTLED_RMT_BUILTIN_DRIVER 1
#define FASTLED_INTERRUPT_RETRY_COUNT 1
In any combination did not resolve the rebooting problem.

Adding

Code: Select all

#define FASTLED_RMT_BUILTIN_DRIVER 1
did turn the LED red when it was supposed to, but then in further testing starting off with green the LED turned blue.

Changing to use:

Code: Select all

FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS)
did correct the LED colour problem, but only if not also using:

Code: Select all

#define FASTLED_RMT_BUILTIN_DRIVER 1
In all cases, the rebooting continued.

I am not overly hung up on using the FastLED library, but like I said others I tried didn't work either.

Still looking for either a solution that will work with FastLED, or in fact any other library usable in the Arduino IDF for the esp32-s2-saola-1.

Who is online

Users browsing this forum: Baidu [Spider] and 34 guests