ESP32 SD Card Interfacing Fast!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a while ago i released a video showing how to use an sd card with the esp8266 in the comments for that video someone asked if you could do the same thing on an esp32 at first i assumed it'd be the exact same you just have to change the pin definitions to match the spi ports on the esp32 it turns out the libraries are a little different and the esp32 actually has a much faster way to interface with sd cards so in this video i'm going to show you how to use the free micro sd card adapters that come with the cards instead of buying a module online i'm going to show you how to interface with it from standard slow spi and then i'm going to show you how to interface with it using the sd mmc host drivers so all right let's get started so the first thing you should know is that you don't have to buy those sd card modules online if your microcontroller runs at 5 volts it's not a bad idea but if your microcontroller is running at 3.3 volts then the microsd card adapter that you get with a card is all you need it's just important that you remember that sd cards operate at 3.3 volts anything above that will damage your card there's no protection built in so you have to be very careful you don't go over 3.3 volts but the esp32 won't have that problem though neither with the esp8266 make sure you know what your microcontroller operates at before you try this so to actually make it all you have to do is solder some mail pin headers to it they line up perfectly with the pads and solder sticks to the pads just fine once that's done you can interface with the sd card directly you don't need any other hardware the sd card itself has its own controller built in that can operate over spi and mmc among other things so this is a great way to save money and it's a nice compact card module [Music] okay so let's hook this up in basic spi mode first make sure you take your sd card out of the adapter then let's look at the card from behind reading the pins from left to right we'll skip the first pin connect the second pin to 19 which is the master in slave out third pin goes to ground fourth pin goes to 18 which is the clock fifth is three point three volts sixth grows the ground again seventh is twenty three master out slave in 8th is 5 which is the chip select and 9th we skip now that we have this connected with basic spi let's move over to the arduino ide the first thing we have to do is make sure the esp32 boards are installed we'll do that by copying a url into the board manager configuration once that's done we can go into the actual board manager search for esp32 and install the boards [Music] when that's done we can browse through the examples and find the esp32 sd card examples that were just added with basic sbi the sd test example just works right out of the box the only thing you'll have to do is make sure you select your own esp32 board before you upload to it it's also worth noting that you should keep your sd cards out of the sd card reader when you program this it might work fine for the basic spi but for the mmc examples you won't be able to program the esp32 while it's in there once programmed put your sd card in the adapter open the serial monitor and reset your esp32 if everything worked correctly you should see a lot of output from the test the key things to note here are the read and write speeds at the very bottom if you're keeping track of what's faster now is a good time to write down those times alright so the basic spi example was pretty easy this is fine if you're occasionally logging small amounts of data for most people that's probably enough but if for some reason you want more speed let's move on to the mmc examples the wiring for the mmc example is different but it's not any more complicated in this case i'm going to hook up all the wires for 1-bit and 4-bit mode but if you're only going to try one bit you can omit the last two wires which is data 3 and data 2. so again looking at the adapter from behind with the pins facing down starting from the leftmost pin number 1 goes to 4 2 goes to pin 2 on the esp32 3 goes to ground 4 goes to 14 5 goes to 3.3 volt 6 also goes to ground 7 goes to 15 [Music] 8 goes to 13 which is d3 and 9 goes to 12 which is d2 again those last two pins you only need for 4-bit mode alright so make sure your sd card isn't in the adapter and let's go back to the ide if you go back to the same directory we got our first example from you'll see another one called sd mmc test open that unfortunately the first time i tried this it didn't work but while browsing around the internet looking for solutions i found a thread on reddit where someone suggested a different way to hook this up which didn't use any additional components like resistors and worked in 1-bit and 4-bit mode so we're going to be modifying this example using the tips i found there the first thing i did is add a define for 1-bit mode that way i can just switch it on and off easily the next thing i did is modify the setup function i enabled a series of internal pull-up resistors and finally in the sd-mmc begin command i added the 1-bit mode variable that i defined earlier this boolean parameter here is how you switch between one bit in four bit mode so with those modifications added let's upload this code and test it remember it won't program with the sd card in the adapter once it's done uploading pop your sd card back in bring up the serial monitor and reset the esp32 if everything worked correctly you should see the same output as last time except everything will be a lot faster it's kind of amazing how much faster one bit mode is but we could still do better this last part will be quick pull your sd card out go back to the ide change the 1-bit mode flag to false reprogram and test again this time you'll notice that the speeds are just a little bit faster than last time is it worth the extra pins probably not but if you do need more speed it's an option so that's the video hopefully now you're ready to take all those adapters you have laying around and turn them into reader modules for your esp32 and 8266 projects thanks for watching you
Info
Channel: ArtsyEngineering
Views: 49,753
Rating: undefined out of 5
Keywords: ESP32, Espressif, SD Card, Free SD Card Module, MMC, SPI, Arduino, Electronics, DIY, Memory Card, Micro SD Card, Tutorial, Walkthrough
Id: e1xOgZsnAuw
Channel Id: undefined
Length: 7min 7sec (427 seconds)
Published: Wed May 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.