This article demonstrates ESP32 MP3 audio playback capability using the PCB Artists ES8388 audio codec module.
There are numerous examples present in the ESP-ADF repository and several of them demonstrate how to play back an MP3 file retrieved from various sources (internal memory, SD card, network location, etc). In this case, the MP3 file is fetched from an SD card. This is one of the best ways to evaluate the audio quality that the ESP32 is capable of producing using a good quality audio codec.
We noticed that the audio playback performance is extremely good with almost no noticeable deterioration in the audio quality compared to a standard smartphone. The codec used here is commonly used in budget smartphones and therefore you can expect the same audio quality in most ESP32 applications. Also, Espressif has definitely done a great job with the MP3 decoding APIs!
ESP32 MP3 Player Demo Components
- ESP32 module (ESP32-PICO-KIT in our case)
- Audio codec (ES8388 module used here)
- SD card (we used a micro SD card adapter)
Interfacing the ESP32 to Audio Codec
- Control link, I2C interface
- Data link, I2S interface
Interfacing the ESP32 to SD Card
For this example to work, you need an SD card that stores the MP3 file. To maintain compatibility with the ESP32 Lyra-T example present in the Espressif ESP-ADF examples directory, we used a certain pinout that is shown below.
You can connect the SD card to the ESP32 module as shown here, using an SD breakout board like this.
Modify the ESP32 MP3 Playback Example from ESP-ADF
A minor modification is required to make the SD card to audio output pipeline example work with this hardware setup.
- Open ESP-ADF example folder at
{ADF_PATH}/examples/player/pipeline_sdcard_mp3 - Inside the main folder, edit file play_sdcard_mp3_example.c to use SPI mode. Locate this line:
// Initialize SD Card peripheral
audio_board_sdcard_init(set, SD_MODE_1_LINE);
Change the above line to use SPI mode as follows:
// Initialize SD Card peripheral
audio_board_sdcard_init(set, SD_MODE_SPI);
Build the MP3 Pipeline Example
You can build the example by switching into that example directory and executing idf.py build.
The build and flash process is similar to the one followed by the ESP32 Bluetooth Audio Player Demo.
Running the Example
Feel free to ask away via the Quick Contact form in the sidebar, or leave a comment below.
Change Log
- Initial Release: 30 May 2021
References
None