SunFounder ESP32 Starter Kit
• In the setup() function, we initialize the SD card, open the MP3 file from the SD card, set up the I2S output
on the ESP32’s internal DAC, set the output to mono, and start the MP3 generator.
void setup() {
// Start the serial communication.
Serial.begin(115200);
delay(1000);
// Initialize the SD card. If it fails, print an error message.
if (!SD_MMC.begin()) {
Serial.println("SD card mount failed!");
}
// Open the MP3 file from the SD card. Replace "/To Alice.mp3" with␣
˓→your own MP3 file name.
file = new AudioFileSourceSD_MMC("/To Alice.mp3");
// Set up the I2S output on ESP32's internal DAC.
out = new AudioOutputI2S(0, 1);
// Set the output to mono.
out->SetOutputModeMono(true);
// Initialize the MP3 generator with the file and output.
mp3 = new AudioGeneratorMP3();
mp3->begin(file, out);
}
• In the loop() function, we check if the MP3 generator is running. If it is, we continue looping it; otherwise, we
stop it and print “MP3 done” to the serial monitor.
void loop() {
// If the MP3 is running, loop it. Otherwise, stop it.
if (mp3->isRunning()) {
if (!mp3->loop()) mp3->stop();
}
// If the MP3 is not running, print a message and wait for 1 second.
else {
Serial.println("MP3 done");
delay(1000);
}
}
1.43 7.6 Take Photo SD
This document describes a project that involves taking a photo using the ESP32-CAM and saving it to an SD card. The
aim of the project is to provide a simple solution for capturing images using the ESP32-CAM and storing them on an
SD card.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
158 Chapter 1. For Arduino User