ESP32-S3 tasks not working
- stevenbennett
- Posts: 34
- Joined: Sun May 19, 2024 7:30 am
- Location: High Bentham, UK
Re: ESP32-S3 tasks not working
After more testing it looks like the library EasyNeoPixels.h somehow interferes with the normal operation of creating and running RTOS tasks, could it have a bug? However the library Adafruit_NeoPixel.h does pretty much the same things but works perfectly with multiple RTOS tasks - who would have guessed!
Last edited by stevenbennett on Fri Aug 30, 2024 2:01 pm, edited 1 time in total.
Re: ESP32-S3 tasks not working
There is nothing wrong with library. You probably need to read logs more carefully.
Some other logs says it crashed due to stack smashing, which mean the stack is too small or you are trying to create local too big local array.FreeRTOS: FreeRTOS Task "flash_task" should not return, Aborting now!
- stevenbennett
- Posts: 34
- Joined: Sun May 19, 2024 7:30 am
- Location: High Bentham, UK
Re: ESP32-S3 tasks not working
OK thanks I will do next time now that I have found out how to enable logs in Visual Studio. I did try various stack sizes from 2000 to 10000, which should be enough, but without success. Not sure what you mean by array but it's a very simple sketch, just flashes a single Neo Pixel.
Re: ESP32-S3 tasks not working
couple tips:stevenbennett wrote: ↑Fri Aug 30, 2024 4:02 pmOK thanks I will do next time now that I have found out how to enable logs in Visual Studio. I did try various stack sizes from 2000 to 10000, which should be enough, but without success. Not sure what you mean by array but it's a very simple sketch, just flashes a single Neo Pixel.
- if you want to use printf, sprintf, serial logs etc in task code then min stack is 3.5-4k
- big arrays allocate with malloc, or as static arrays or just use global variables
- its better to start with bigger stack, just not too big, 10k may be too much, but +/-6k is good starting point
Re: ESP32-S3 tasks not working
You have and did show the log already, it said that flashTask() returned instead of looping forever.
And that does correspond to the code you posted (the while loop is missing):
Code: Select all
void flashTask(void *pvParameter)
{
digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
delay(1000);
digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
delay(1000);
}
But it did cause some confusion anyway.
- stevenbennett
- Posts: 34
- Joined: Sun May 19, 2024 7:30 am
- Location: High Bentham, UK
Re: ESP32-S3 tasks not working
Sorry about the confusion I was trying different things to get tasks working and it made no difference to the symptoms of the problem. My objective was to get tasks working on an ESP32-S3 as I had had no problems with an ESP32. I wasn't interested in flashing NeoPixels particularly. So I wasn't that interested in finding out why the FastLED.h library did not work for me when the Adafruit_NeoPixel.h worked flawlessly out of the box - stuffing mushrooms came to mind. Anyway after some tinkering everything is working perfectly so for anyone wanting a template for tasks on an S3 and possibly flash a NeoPixel this is the final code:
/*
* This sketch uses two RTOS tasks to print to serial and flash the on-board NeoPixel
* Adafruit_NeoPixel Class Reference: https://adafruit.github.io/Adafruit_Neo ... pixel.html
* NOTE: On ESP32xx MCUs delay() calls vTaskDelay() and is therefore interchangeable,
* see: https://github.com/espressif/arduino-es ... #L202-L204
*/
#include <Adafruit_NeoPixel.h> // A library to control one, or more, NeoPixel LEDs
int PIN = 48; // The NeoPixel RGB LED is connected to pin 48 on the ESP32_S3_DevKitC_1 module, and is a WS2812B device, see: https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
int DELAYVAL = 500; // Common delay value between colour changes
int count = 0; // A test value
Adafruit_NeoPixel pixels(
1, // Number of NeoPixel LEDs
PIN, // GPIO pin connected to NeoPixel
NEO_GRB + // Define type of NeoPixel, in this case RGB means RED, GREEN & BLUE, some are GRB. For pixels.Color NEO_RGB = (G,R,B) and NEO_GRB = (R,G,B) strangely! Probably only impacts strings of NeoPixels.
NEO_KHZ800 // Interface speed for NeoPixel device, usually 400 or 800
);
void setup() {
Serial.begin(115200);
pixels.begin(); // INITIALIZE NeoPixel object (REQUIRED)
xTaskCreate(printTask, "print_task", 5000, NULL, 1, NULL); // Create print_task
xTaskCreate(flashTask, "flash_task", 5000, NULL, 1, NULL); // Create flash_task
}
static void printTask(void *pvParameter)
{
while (1) {
Serial.print("printing = ");
Serial.print(count);
Serial.println();
vTaskDelay(15000 / portTICK_PERIOD_MS); // Delay for 15000mS
}
}
static void flashTask(void *pvParameter)
{
while (1) {
Serial.println("flashing");
pixels.clear(); // Set all pixel colours to 'off'
pixels.show(); // Send the updated pixel colours to the hardware.
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000mS
// The first NeoPixel in a strand is #0, second is 1 et cetera
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(0, pixels.Color(10, 0, 0)); // Red using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
pixels.setPixelColor(0, pixels.Color(0, 10, 0)); // Green using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
pixels.setPixelColor(0, pixels.Color(0, 0, 10)); // Blue using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
void loop() {
count++; // This variable starts at 0 and increments every 1000mS
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000mS
}
/*
* This sketch uses two RTOS tasks to print to serial and flash the on-board NeoPixel
* Adafruit_NeoPixel Class Reference: https://adafruit.github.io/Adafruit_Neo ... pixel.html
* NOTE: On ESP32xx MCUs delay() calls vTaskDelay() and is therefore interchangeable,
* see: https://github.com/espressif/arduino-es ... #L202-L204
*/
#include <Adafruit_NeoPixel.h> // A library to control one, or more, NeoPixel LEDs
int PIN = 48; // The NeoPixel RGB LED is connected to pin 48 on the ESP32_S3_DevKitC_1 module, and is a WS2812B device, see: https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
int DELAYVAL = 500; // Common delay value between colour changes
int count = 0; // A test value
Adafruit_NeoPixel pixels(
1, // Number of NeoPixel LEDs
PIN, // GPIO pin connected to NeoPixel
NEO_GRB + // Define type of NeoPixel, in this case RGB means RED, GREEN & BLUE, some are GRB. For pixels.Color NEO_RGB = (G,R,B) and NEO_GRB = (R,G,B) strangely! Probably only impacts strings of NeoPixels.
NEO_KHZ800 // Interface speed for NeoPixel device, usually 400 or 800
);
void setup() {
Serial.begin(115200);
pixels.begin(); // INITIALIZE NeoPixel object (REQUIRED)
xTaskCreate(printTask, "print_task", 5000, NULL, 1, NULL); // Create print_task
xTaskCreate(flashTask, "flash_task", 5000, NULL, 1, NULL); // Create flash_task
}
static void printTask(void *pvParameter)
{
while (1) {
Serial.print("printing = ");
Serial.print(count);
Serial.println();
vTaskDelay(15000 / portTICK_PERIOD_MS); // Delay for 15000mS
}
}
static void flashTask(void *pvParameter)
{
while (1) {
Serial.println("flashing");
pixels.clear(); // Set all pixel colours to 'off'
pixels.show(); // Send the updated pixel colours to the hardware.
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000mS
// The first NeoPixel in a strand is #0, second is 1 et cetera
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(0, pixels.Color(10, 0, 0)); // Red using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
pixels.setPixelColor(0, pixels.Color(0, 10, 0)); // Green using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
pixels.setPixelColor(0, pixels.Color(0, 0, 10)); // Blue using NEO_GRB
pixels.show(); // Send the updated pixel colours to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
void loop() {
count++; // This variable starts at 0 and increments every 1000mS
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000mS
}
Who is online
Users browsing this forum: No registered users and 128 guests