Hi everyone,
I’m trying to build a Bluetooth audio receiver that outputs a Bluetooth signal via AUX on the ESP32. Unfortunately, my ESP32 keeps crashing and I get the following error:
E (46579) task_wdt: Task watchdog got triggered. IDLE0 (CPU 0)
The issue seems related to a watchdog timeout. My code starts running, but ESP restarts as soon as i start playing music/sound. I suspect the audio processing is blocking the watchdog or consuming too much memory.
Here’s a snippet of my code (Arduino IDE):
#include <Arduino.h>
#include "BluetoothA2DPSink.h"
#define LED_PIN 15 // Status LED
/*
BCK 26
DIN 22
LCK 25
*/
BluetoothA2DPSink a2dp_sink;
// Stream callback: called when music data is received
void streamCallback(const uint8_t *data, uint32_t length) {
digitalWrite(LED_PIN, HIGH); // LED on when streaming
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
// Start Bluetooth A2DP sink
a2dp_sink.start("ESP32_Bluetooth");
// Set callback for incoming audio stream
a2dp_sink.set_stream_reader(streamCallback);
}
void loop() {
// If no audio for a while, turn off LED
static unsigned long lastTime = 0;
if (millis() - lastTime > 3000) { // 3 seconds timeout
digitalWrite(LED_PIN, LOW);
}
}
What I’ve already tried:
Extending the task watchdog timeout
Distributing tasks across both CPUs
Unfortunately, none of this worked.
I don't want to completely daectivate watchdog!?
My questions:
Has anyone encountered this issue and knows how to reliably fix it?
Are there best practices for Bluetooth audio on the ESP32 to avoid watchdog timeouts?
Thanks in advance for any help!
Audio Receiver: Watchdog Timeout | PCM5102a + ESP32
-
ESPplsWORKK
- Posts: 1
- Joined: Sun Oct 26, 2025 11:41 am
-
MicroController
- Posts: 2661
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Audio Receiver: Watchdog Timeout | PCM5102a + ESP32
This loop consumes basically 100% of the CPU. Chances are that when another activity (audio...) is also running, the IDLE task gets no CPU time at all, which causes the watchdog timeout.void loop() {
// If no audio for a while, turn off LED
static unsigned long lastTime = 0;
if (millis() - lastTime > 3000) { // 3 seconds timeout
digitalWrite(LED_PIN, LOW);
}
}
Try replacing the loop with something like
Code: Select all
void loop() {
delay(1000);
}
Who is online
Users browsing this forum: Baidu [Spider], meta-externalagent, PetalBot and 9 guests