I want to play two audio files one after another on an SD card with an ESP32.
My code is below but does not work, I am pulling my hair out to work out why....
I know wiring is correct as single audio files can be played when audio.connecttoFS(SD, "charging.mp3"); is placed in setup as per demo code I based script on but won't work when called from main loop.
/* ESP32 SD I2S Plays MP3 file from microSD card Uses MAX98357 I2S Amplifier Module Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S */ // Include required libraries #include "Arduino.h" #include "Audio.h" #include "SD.h" #include "FS.h" // microSD Card Reader connections #define SD_CS 5 #define SPI_MOSI 23 #define SPI_MISO 19 #define SPI_SCK 18 // I2S Connections #define I2S_DOUT 26 #define I2S_BCLK 27 #define I2S_LRC 25 // Create Audio object Audio audio; void setup() { // Set microSD Card CS as OUTPUT and set HIGH pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH); // Initialize SPI bus for microSD Card SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); // Start Serial Port Serial.begin(115200); // Start microSD Card if(!SD.begin(SD_CS)) { Serial.println("Error accessing microSD card!"); while(true); } // Setup I2S audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); } void loop() { audio.setVolume(15); audio.connecttoFS(SD, "charging.mp3"); delay (10000); audio.connecttoFS(SD, "fire-full_power.mp3"); }
My daughter asked the question "I want my pottery to play a sound, running water".
After a load of searching KISS kicked in. On ebay I found a thumb nail sized amplifier/SD card reader/serial or push switch control. Dirt cheap. So I wired this to a small Pico ( python is encouraged for young people in the UK ) and used the serial output to control the player. The two modules are about the same size as one ESP32.
Brutal overkill but it worked, triggered by a small PIR.