Arduino: Interfacing SD card with ESP 32
|In our previous blog we have seen how to setup arduino for ESP 32 and ran GetChipID example, in this blog we will see how to run the SD_Test example.
Connecting ESP DevKit to SD Card Breakout board
if you have a SD card breakout board you can directly connect it respective connections on ESP32 dev board like MISO to MISO,SCK to SCK etc.. (The Breakout board might have a VCC pin, Connect 3v3 to that pin)
You can find the program in Examples -> SD(esp32) -> SD_Test
open the serial console after loading the code, the program will print basic information about the SD card and it will write and read a file as well
Followings are results when executed the testFileIO function with different buffer sizes
1 byte buffer
- 1048576 bytes read for 14522 ms
- 2048 bytes written for 33 ms
- 2048 bytes read for 28 ms
128 byte buffer
- 262144 bytes read for 869 ms
- 262144 bytes written for 1714 ms
512 byte buffer
- 1048576 bytes read for 3432 ms
- 1048576 bytes written for 7155 ms
4096 byte buffer
- 8388608 bytes read for 27322 ms
- 8388608 bytes written for 29227 ms
18 Comments
hi,
found your website very helpful. Can u please explain about the SPI communication programming of esp32 using esp-idf. Since I’m doing a project on it, It would be really great if u could help.
thanks you,
your work is really appreciable.
Hi,
Thanks.
You can read about using esp32 with esp-idf here
you can also use eclipse to program esp32
I didn’t get your question about SPI, could you please elaborate
Hi Sankar, I am trying to connect micro sdcard module from xcluma to my esp32 and tryout a sdcard example program from espressif by pcbreflux.
The link is as below.
https://github.com/pcbreflux/espressif/tree/master/esp32/app/ESP32_sd_card
The link that shows what sdcard module I use is below.
https://www.xcluma.com/interface-boards/interface-boards-memory-storage/micro-sd-card-module-tf-card-memory-shield-sd-storage-boad-for-arduino
This looks just like you have in the picture. My connections are done but I am getting an error saying I need to have pullups on the pins.
Can you try this with your connections and let me know if it works for you.
Regards
Shraddha
Hi,
which mode you are using ?
Hi Sankar , can you explain on how to interface ESP 32 with Arduino Due Sam3x8e
The SD_Test sketch won’t recognize the SD card. I wrote a little program to
print out the values (pin numbers) for variables SS, MOSI, etc. It is giving me
a 2 for SS. There is no pin 2 on my ESP32. The SD_Test won’t allow me to
re-assign a value for SS. Do you have any suggestions?
Chuck
SD.begin() allows the CS pin (SS) to be defined when started. Just put in the number of the pin when it’s called in the code. e.g. SD.begin(5)
5 is the default SS pin on ESP32 btw.
When I try this on a Wemos D1 mini ESP32 clone (using standard SPI pins 18/19/23/5), I get:
[E][sd_diskio.cpp:739] sdcard_mount(): f_mount failed 0x(3)
Any suggestions? I have tried multiple SD cards (2/4/8/16/32Gb) with varying formats (FAT/FAT32 – all of which I have used on atmel/arduino based SD card projects with the same formats)
Hi,
How do you connect sd card with esp32 devkit in SD mode
hadware : node mcu -esp32
software: arduino
used esp32 espressif library
Trying to store data in SD card using SD card module.
Code: SD Test code
No compiling error
Card initialised
But then shows error
assertion “0 && “fatfs internal error”” failed: file “/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/fatfs/src/vfs_fat.c”, line 253, function: fresult_to_errno
Serial Monitor output :
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9220
load:0x40080400,len:6300
entry 0x400806a4
SD Card Type: SDHC
SD Card Size: 14804MB
Listing directory: /
assertion “0 && “fatfs internal error”” failed: file “/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/fatfs/src/vfs_fat.c”, line 253, function: fresult_to_errno
abort() was called at PC 0x400db19b on core 1
Backtrace: 0x40085e88:0x3ffb1ba0 0x400860b5:0x3ffb1bc0 0x400db19b:0x3ffb1be0 0x400d995f:0x3ffb1c10 0x400da393:0x3ffb1c30 0x400dae19:0x3ffb1da0 0x4000bcc5:0x3ffb1dc0 0x400dba11:0x3ffb1de0 0x400d17af:0x3ffb1e00 0x400d1b47:0x3ffb1e30 0x400d1cc2:0x3ffb1e70 0x400d1491:0x3ffb1ee0 0x400d0fe3:0x3ffb1f10 0x400d1375:0x3ffb1f80 0x400edce7:0x3ffb1fb0 0x4008767d:0x3ffb1fd0
Rebooting…
This card and module perfectly works with Uno but error shown with esp32.
Can anyone help?
Been searching everywhere to make this thing work and still cannot find answers.
Hopefully someone here can help.
Same MicroSD Card Adaprter
ESP 32S v.1.1
Wired:
SS -> 5
SCK -> 18
MISO -> 19
MOSI -> 23
Brand new install
OS: Mac OSX 10.12.6
Aurdino IDE: 1.8.8
Using same example SD(esp32)
Result: Card Mount Failed
Hola!
sigo tratando de resolver el mismo problema que tú,
ya lo pudiste resolver ?
Hi!
a hev the same error that you.
have you solved it?
Hi. I have an SD card reader that looks very similar to the one in the article (branded “CATALEX”) except that connecting it to 3.3 volts resulted in an error.
It required 5 volts on VCC and the four signal pins, so I used a level shifter to make it work with the ESP32 and the SD(ESP32) sketch.
Hi, Anyone solved it ?
I have the same problem.
I need to read line by line and store data in a 2-dimension array… can you help me?
Hi,
You need to connect 10k pullups in all the 4 SPI line to make it to work.
hi sir, can i partition the size of the esp32 module of 4mb