A detailed look at how to play WAV’s from SD without using 3rd party libraries for transfer of WAV’s to I2S. It should give you enough detail to add this into your own code/wav players. Video Below which goes through everything and sources code/diagrams afterwards.
INTRO
As always time-codes are available in the video description. It’s recommended you watch the previous episodes (Ep1, Ep2). If you watched the last episode you’d have quickly realised that playing high quality WAV files is not possible on the ESP32 as the file sizes are just too big. You have to compromise and reduce quality a lot. The solution is some external storage.
Parts List
All parts you see are available as affiliate links below, costs no more to you but I get a very small commission if you buy through the link.
ESP32 : https://amzn.to/3kb02n8
ESP32 – Pack of three : https://amzn.to/2XfIRqH
I2S Decoder : MAX98357A : https://amzn.to/3fkHEnU
SD Card Reader : https://amzn.to/2Q9Fb5V 3W
Speaker : https://amzn.to/2XeRP7i
Breadboards : https://amzn.to/30fWibZ
Wires : https://amzn.to/3k4PKoC
Pins and sockets : https://amzn.to/39O7a3K (I2S board doesn’t come with them)
The Circuit – Diagram
This is the full diagram but the real life photo’s only show the SD card connections. For pictures and descriptions of the rest of the real circuit please see the previous articles in this series (linked at the top).
Circuit – Real Life
SD Card Connection Descriptions
So we have the red and black wires going to the 3.3v rail and ground respectively. Blue is the MOSI wire going from MOSI of the SD card to pin 23. The pink wire is MISO and goes to pin 19. Yellow is the clock -SCK-, that goes to pin 18. And finally green is chip select – CS – and that finds its home on pin 5.
SD card
What can we put on the SD card? For this simple test the file must be called “wavfile.wav”. It must be a stereo 16 bits per sample file. But any sample rate is fine.
DEMO
As mentioned in the video only the last demo is available here. The reason is that only the last one works properly. The first two we showing the pitfalls of delivering I2S data from SD Card.
Round up
So that wraps up another episode in this series, this one was quite heavy on the detail. So in the next article we’ll take things down a level and look at how you can control the volume of your output,as at the moment it plays quite loud, or at least it would if I hadn’t artificially lowered it using Audacity. Please consider subscribing to the channel if your not already a subscriber. And last but certainly not least, thank you all very much for reading/watching, especially if you made it to this point. Till next time…
Thanks for your tutorials!
I’ve got this example up and running, but for some reason I have to set the sample rate to 1/2 of the actual rate or else it’ll play double speed.
Any ideas on why that might be happening?
I’m stabbing in the dark a little here but I’d check that the bits per sample etc. of your sound match what it’s setting it too.
Thanks for the reply!
Turns out I was using mono sounds which was causing the sample rate miss match. Ez fix 🙂
Thanks again for your help and tutorials!!!
Brilliant!
hi,
sound stops after 2 seconds
i tried with different sd cards.
also the program is not starting itself, – sound arrives only after powering off/ ON
i connect to 5V
how to upload image and video ?
thanks your effort
guten tag aus austria
rudi
So program does not start itself after upload but switching off and on again and it does start itself? That’s odd. Does it do that with other code uploaded to the ESP32?
Sound stops after 2s, do you have any other devices attached to your esp32 (display etc.)
What do you mean by image and video, do you want to send these to a display?
Thanks!!!
Your welcome 🙂
Could You please advise me how to change speed during playing?
I have tested “set samplerate..” but without success.