r/arduino • u/squeakyhedge • 2d ago
Software Help Stuck with ESP32-audioI2S crashing my program
Hello guys, I've been struggling with this problem for a few days already, and i just can't find the solution. I am using an ESP32-S3-WROOM-1 with platformIO and have written a simple program that uses the ESP32-audioI2S library to attempt to play a file from an SD card.
#include <Arduino.h>
#include <SD_MMC.h>
#include <Audio.h>
#include "pins.h"
#include <Wire.h>
#include "scan.h"
#include "amp.h"
#include "esp_heap_caps.h"
Audio audio;
void my_audio_info(Audio::msg_t m) {
Serial.printf("%s: %s\n", m.s, m.msg);
}
void setup() {
Serial.begin(9600);
delay(1500);
SD_MMC.setPins(PIN_SDIO_CLK, PIN_SDIO_CMD, PIN_SDIO_D0, PIN_SDIO_D1, PIN_SDIO_D2, PIN_SDIO_D3);
if (!SD_MMC.begin("/sdcard", false, false, 5000)) {
Serial.println("SD card init failed");
} else {
Serial.println("SD card init success");
}
Serial.printf("Total PSRAM: %d bytes\n", ESP.getPsramSize());
Serial.printf("Free PSRAM: %d bytes\n", ESP.getFreePsram());
Serial.printf("Largest free block in PSRAM: %d bytes\n", heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM));
Audio::audio_info_callback = my_audio_info;
audio.setPinout(PIN_I2S_BCK, PIN_I2S_LRCK, PIN_I2S_DOUT);
audio.setVolume(21);
if (!audio.connecttoFS(SD_MMC, "/sample-3s.mp3")) {
Serial.println("failed to connect to mp3");
}
delay(100);
}
void loop() {
audio.loop();
vTaskDelay(1);
}When running the code, I get the following in the serial monitor:
SD card init success
Total PSRAM: 2097152 bytes
Free PSRAM: 2065324 bytes
Largest free block in PSRAM: 2064372 bytes
info: inputBufferSize: 655349 bytes
info: Reading file: "/sample-3s.mp3"
Disconnected (read failed: [Errno 6] Device not configured)
Reconnecting to /dev/cu.usbmodem7C0C5F964D501 . Connected!After the "info: Reading file:" line, the firmware crashes and reboots. At first I thought there was not enough memory, but i printed the available PSRAM and its way more than the buffer size. Maybe the library was not told to use PSRAM? But I couldn't find a way to do that. What in the world is this issue?
