Learn how to use the ESP32 to record and play WAVE files to and from an SD Card with ease, using the Arduino framework.
[0:00] Hey Everyone,
[0:01] In this video, we’re going to be using the ESP32 to record and play WAVE files to and from an SD Card.
[0:09] This video was prompted by a viewer who’s been having a nightmare trying to get this to work.
[0:13] I thought - How hard can it be?
[0:16] I already had an SD Card capable board with my M5 Core2 Stack
[0:20] but I hadn’t actually managed to make it recognise any SD Cards.
[0:24] So I ordered a breakout board to see if I could make it work on a generic dev board.
[0:30] As soon as I’d ordered, I looked through all my old components and found I already had a breakout board.
[0:35] Along with a couple of other dev boards with SD Card slots.
[0:39] With an abundance of equipment to hand, I went in search of a library.
[0:43] This is where I discovered that breakout boards are completely unnecessary
[0:46] and that SD Cards have an SPI interface that can be wired directly to an ESP32.
[0:52] Next time I’ll do my research first.
[0:55] Wiring up is pretty straight forward, we need a 3.3V and two GND lines.
[1:00] With these taken care of we just need the four lines for SPI - MISO, MOSI, CS and CLK.
[1:07] I’ve got quite a few of these micro SD Card adaptors lying around,
[1:11] so I set the soldering iron as low as it would go and tinned up the connectors.
[1:19] With the connectors tinned I just reflowed some wires and made up a breadboard friendly plug.
[1:27] There’s a bit of plastic meltage, but it’s not too bad.
[1:30] With the card wired up, I tried it on the Arduino example for reading and writing to an SD Card.
[1:36] Depressingly this completely failed.
[1:44] After many attempts to get this working,
[1:46] I tried one of the SD Cards that I use for my Raspberry PI
[1:50] and it worked!
[1:52] The only difference between the cards that work and the ones that don’t
[1:55] is that the working ones are marked with XC and the failing ones are marked with HC.
[2:01] And also, the working ones are also a lot more expensive.
[2:05] Before giving up on my cheap SD cards I thought I’d try the sample code from the latest IDF version.
[2:10] Surprisingly it works on all the cards.
[2:14] With a bit of messing around, I’ve managed to backport the working code to the version
[2:18] of the IDF that Arduino comes with and I now have it working with the Arduino framework
[2:23] and all the SD Cards that I have.
[2:25] Let’s see it in action - there’s not much to see
[2:29] but we can record some audio by pushing and holding a button.
[2:41] And then we can play it back by tapping the button again.
[2:52] If we plug the SD Card into the computer we can see the file that has been recorded.
[3:02] And we can load it into Audacity and play it.
[3:11] There’s one thing to note:
[3:13] The SD Card should be formatted as FAT32
[3:16] I believe the code also supports FAT16, but I have not tried it.
[3:21] The code is pretty straight forward so should be easy enough to follow but it does use FreeRTOS tasks,
[3:27] I2S and DMA transfers
[3:29] So there are some fairly advanced concepts to get your head around.
[3:33] As usual, the code is all on GitHub - the link is in the description
[3:37] I’d be really interested to hear how you get on with it and which SD Cards do and don’t work.
[3:42] I think I might turn this into a nice little voice memo project so stay tuned for the next video.
[3:48] Thanks for watching!
[3:49] And I’ll see you soon!