One of the tasks attached to a core doesn't run
Posted: Sat Feb 03, 2024 12:20 am
Hey everyone! I have an ESP32-S3 (attached to a Sunton display) and I want it to perform two tasks: displaying video that an ESP32-CAM transmits and blinking an LED (below is the main code):
The task for displaying video looks like this:
And the task for blinking an LED looks like this:
Something I don't get is that the first declared task in the main code is the one that runs (no matter the priority or the core), which means that if I declare the video transmission task first, that only task runs. But if I declare the blinking LED first, that only task runs.
I've already tried by changing their running core, stack size and even running them both on the same core and deleting the setup() and loop() functions.
Any idea why this happens? Thanks in advance
- #include <Arduino.h>
- #include "tasks.hpp"
- TaskHandle_t video;
- TaskHandle_t led;
- void setup() {
- Serial.begin(115200);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- Serial.println();
- Serial.println("---SICABS Indoor---");
- Serial.println();
- xTaskCreatePinnedToCore(videoProjection, "Video projection", 200000, NULL, 1, &video, 1);
- xTaskCreatePinnedToCore(blinkLED, "blink LED", 200000, NULL, 1, &led, 0);
- }
- void loop() {
- vTaskDelete(NULL);
- }
- void videoProjection(void* parameter) {
- gfx.init();
- gfx.setRotation(0);
- gfx.setColorDepth(16);
- gfx.setBrightness(127);
- gfx.fillScreen(TFT_BLACK);
- gfx.setSwapBytes(true);
- gfx.setFont(&fonts::lgfxJapanGothic_16);
- gfx.drawString("SICABS Indoor", 0, 0);
- // JPEG decoder
- TJpgDec.setJpgScale(1);
- TJpgDec.setCallback(tft_output);
- // WiFi
- WiFi.softAP(wifi_ssid, wifi_password);
- IPAddress IP = WiFi.softAPIP();
- // WebSockets
- server.listen(SERVER_PORT);
- Serial.print("Video task running on core ");
- Serial.println(xPortGetCoreID());
- for (;;) {
- if (server.poll()) {
- // if (!client.available()) { // Always overwrite the client to the new one
- client = server.accept();
- client.onMessage(onMessageCallback);
- client.onEvent(onEventsCallback);
- client.send("Hello Client!");
- // }
- }
- if (client.available()) {
- client.poll();
- }
- }
- }
- void blinkLED(void *parameter) {
- int time = 1000;
- pinMode(led_pin, OUTPUT);
- Serial.print("Blinking LED task running on core ");
- Serial.println(xPortGetCoreID());
- for (;;) {
- digitalWrite(led_pin, HIGH);
- vTaskDelay(time / portTICK_PERIOD_MS);
- digitalWrite(led_pin, LOW);
- vTaskDelay(time / portTICK_PERIOD_MS);
- }
- }
I've already tried by changing their running core, stack size and even running them both on the same core and deleting the setup() and loop() functions.
Any idea why this happens? Thanks in advance