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?