ESP8266 NodeMCU SD Card Not Initializing

I have tried numerous tutorials, Arduino examples and I cant get an SD to initialize. There is a card inserted that is formatted with exFAT and there is one file test.txt. Particularly SD Card Module With ESP8266 and ESP8266 (NodeMCU) and SD Cards.

I'm using this SD card module, Micro SD SDHC TF Card Adapter Reader Module with SPI Interface Level Conversion Chip Compatible with Arduino Raspberry PI 10pcs. I soldiered the pin connector to the SD card so it would easily set in the breadboard.

Here are a few pics of my breadboard setup:



void SDsetup()
{
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

File Textfile;
Serial.begin(9600);
Serial.println("Initializing SD card");

if (!SD.begin(15)) {  
    Serial.println("Initialization failed!");  
    return;
}

Serial.println("Initialization completed"); 
Textfile = SD.open("test.txt", FILE_WRITE);  

if (Textfile) {
    Serial.println("Writing to Textfile...");  
    Textfile.println("First line");    
    Textfile.println("1, 2, 3, 4, 5");
    Textfile.println("a, b, c, d, e");
    Textfile.println();
    Textfile.close();     
    Serial.println("Completed");       
    Serial.println();
}
else {
    Serial.println("Text file could not be read");  
}

// READ TEXTFILE
Textfile = SD.open("test.txt");      
if (Textfile) {
    Serial.println("test.txt:");    
    while (Textfile.available()) {
    Serial.write(Textfile.read());     
    }
    Textfile.close();    
}
else  {
    Serial.println("Text file could not be opened"); 
}
}

The serial output:

none

smart setup

Initializing SD card

Initialization failed!

smart loop

I found this Filesystem — ESP8266 Arduino Core 3.1.2-21-ga348833 documentation and surprisingly SPIFFS sort of worked. It initialized but had problems with read/write.

File Textfile;
Serial.begin(9600);
Serial.println("Initializing SD card");

if (SPIFFS.begin()) {
    Serial.println("Siffs success");
    Textfile = SPIFFS.open("test.txt", "w");
    if (Textfile) {
        Serial.write(Textfile.read());
        Serial.println("Writing to Textfile...");
        Textfile.println("First line");
        Textfile.println("1, 2, 3, 4, 5");
        Textfile.println("a, b, c, d, e");
        Textfile.println();
        Textfile.close();
        Serial.println("Completed");
        Serial.println();
        Serial.write(Textfile.read());
    }
}
else {
    Serial.println("Text file could not be read");
}
if (!SD.begin(15)) {
    Serial.println("Initialization failed!");
    return;
}

The above code produced the below log:

Initializing SD card

Siffs success

�Writing to Textfile...

Completed



�Initialization failed!

Why cant I get either one to work properly? What am I missing?

Does the SD.h library for the ESP8266 support exFAT? I don't think it does for AVR. You might try using a smaller card and FAT32 to see if that makes a difference.

Also, the 3V output of the MCU module may not be able to provide enough power for an SD card. You might just check to see if you're getting any voltage sag on that line while attempting to initialize the card.

I just found out no it doesnt. I was referred to sdcard.org to download a formatting tool since Windows wont allow me to format in just FAT. I figured since they are both FAT it should work. But that was not correct.

I think 32GB is magic size for SDHC, which is what works with FAT32. Anything larger than that and Windows should balk at formatting with FAT32. SDXC goes with exFAT as I remember.

However, I think the SdFat.h library does support SDXC and exFAT. You could use that instead of SD.h.