8000 ESP8266 NodeMCU SD Card Not Initializing · Issue #9156 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content
ESP8266 NodeMCU SD Card Not Initializing #9156
Open
@jcrosby10

Description

@jcrosby10

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:

Breadboard setup#1

Breadboard setup#2

Breadboard setup#3

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:

smart setup
Initializing SD card
Initialization failed!
smart loop

I found this https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#file-system-object-spiffs-littlefs-sd-sdfs 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0