ESP32 DOIT Devkit V1 cannot recognise any SD cards

I have been spending now the better part of my day today trying to get my ESP32 to recognise any SD card, but without luck.

I’m using the Arduino framework, and I’m using the SD.h and SPI.h library, and I’ve tried multiple example codes now from different people, all with the same errors. The ESP32 itself has been running just fine for a couple of weeks now where I’ve been testing some other code on it, which it still runs just fine.

I’ve tried using a 4GB SD card, a 16GB SD card, and a 64GB SD card. 16 GB and 64 GB should be working just fine, and in fact I stole and formatted the 16GB card right out of my Raspberry Pi, and the 4 GB I found in a drawer. I’ve formatted the cards now multiple times to FAT32 and FAT16, from Gparted on my Ubuntu machine and from a Windows machine as well.

My SD card module is a simple breakout board with some pull ups and caps on it.

For the two 16 GB and 64 GB cards, I get one error, and for the 4 GB I get another error.

16 + 64 GB error:

[   499][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x37
[   500][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x29
[   501][E][sd_diskio.cpp:795] sdcard_mount(): f_mount failed: (3) The physical drive cannot work

4 GB card error:

[   935][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x11
[   936][E][sd_diskio.cpp:795] sdcard_mount(): f_mount failed: (1) A hard error occurred in the low level disk I/O layer

The code I’m currently running looks like this, however, I’ve tried many different example codes now, all with the exact same problem.

/** This program tests the SD card module is working */
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>

/** The clock select pin for the SD card module */
#define CS_PIN 5

void setup() {

  // Initialize the Serial (it'll tell us if the program runned correctly)
  Serial.begin(115200);
  while (!Serial) { }

  // Check the module is connected
  if (!SD.begin(CS_PIN)) {
    Serial.println("Error, SD Initialization Failed");
    return;
  }

  File testFile = SD.open("/SDTest.txt", FILE_WRITE);
  if (testFile) {
    testFile.println("Hello ESP32 SD");
    testFile.close();
    Serial.println("Success, data written to SDTest.txt");
  } else {
    Serial.println("Error, couldn't not open SDTest.txt");
  }
}

// Do nothing, sd card operations run on setup()
void loop() {}

I have attached screenshots of the SD cards, of my setup, and of the SD card module.

I have no clue why any of this doesn’t work, and I feel like I’ve drained any Google-able combination of words I can think of. Please help :slight_smile:




Does this occur in the Arduino IDE using the latest Arduino-ESP32 core too?

Embarrassingly, it was a loose connection in my breadboard. I hope someone else will stumble over this and double check their connections :smile:

1 Like

Fxcking breadboard, I will never trust a breadboard again