Playing MP3’s (and other types) on your ESP32 from an SD Card

How to play MP3’s and other file formats on your ESP32 from an SD Card. All you need to know to make a simple music player. Code shown in video is below.

Links:
Github page for the library used : https://github.com/schreibfaul1/ESP32-audioI2S

Affiliate links for the items shown: Clicking these costs you the same price but gives me a small commission, please consider supporting this channel by using them 🙂

MAX98357A : https://amzn.to/3eovdrd
(You will need two of these for stereo sound)

ESP32 : https://amzn.to/2Xzhc3k

Breadboards: https://amzn.to/2THZTvy

Speakers : https://amzn.to/2zBhK0F

16Gb SanDisk SD card : https://amzn.to/2XH1sLA

SD Card Reader, note this is the only one I could quickly find that said it supported 3.3v and it’s for the normal size SD cards not Micro, you could always by a micro one and do my hack
https://amzn.to/2ApOppK

The Demo Code

18 Comments

  1. Thank you very much for this post.
    Working good with .mp3 files.
    But not working with .wav files.
    What can be the reason?

    • Sorry for late reply, real life work has been very busy and I missed this comment. I imagine it’s the library that has a problem. Although WAV’s are the simplest files to play. I did have issues with AAC files. I would try different WAV’s, i.e. different sample rates and stereo/mono and see what happens for them.

  2. Is there any way to pull the “audio.connecttoFS(SD,”/Amaze.mp3″);” part out of the setup block and into its own function? Basically so I can have multiple files that play on different button presses. Something like this:

  3. Hi, I have tried the same setup and code for single speaker with MAX98357A Mono amplifier. But only noise is coming out. I have tried both .mp3 and .wav file. But it’s not working. I have tested micro sd card module which is working fine. Could you help how to play mp3 using single speaker with single MAX98357A module ?

    • If I remember rightly this happened to me, it was just a wiring issue, are you sure that all the wires that must be connected are and that they go to the correct ground or vcc. Some connections even though not going to the esp32 must be connected as shown.

  4. Thanks a lot XTronical. It was connectivity issue. Also, I have connected gain pin to ground to reduce noise signal. I have one more query, have you ever tried playing mp3 file from sd card using ESP32 touch pins using the same code/library ? I tried but no sound is coming. In case, if you know, please help me to resolve the issue.

  5. After play the song i move on to next task, but it remain in a loop audio.loop(). How it exit after play the song?

  6. Hi I getting Error compiling this code,
    Audio audio; was not name a type,
    can you share the Audio library that used at this code ??
    Thanks in advance

    • If you look just under the you tube video (very near top of article) you’ll find the link to the library used on Github, it’s under a heading called links.

  7. Hi, I had tried the same code and same connection, but there is no sound coming out. I am connecting one 4 ohm speaker to max98357a. May I know is there any requirement on the file size for mp3 ?

    • One speaker only per output connection to the 98357a is correct. There are no particular restrictions on file size of the mp3. It should handle mp3’s of many megs (10’s of minutes) without issue if not longer. I find when I was first setting up the 98357 that you had to ensure all wires are connected exactly as shown or it may not work

Comments are closed.