#include <SD.h>
#include <SPI.h>
#define CS_PIN 5
File root;
void setup() {
Serial.begin(115200);
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true);
}
Serial.println("Initialization done.");
// Example of writing to a file on the SD card:
File writeFile = SD.open("/wokwi.txt", FILE_WRITE);
if (writeFile) {
Serial.println("Writing to example.txt...");
writeFile.println("Hello from ESP32!");
writeFile.close();
Serial.println("Write done.");
} else {
Serial.println("Error opening wokwi.txt for writing!");
}
// Example of reading a file from the SD card:
File readFile = SD.open("/wokwi.txt");
if (readFile) {
Serial.println("Reading from wokwi.txt:");
while (readFile.available()) {
Serial.write(readFile.read());
}
readFile.close();
Serial.println("\nRead done.");
} else {
Serial.println("Error opening example.txt for reading!");
}
}
void loop() {
// Nothing to do here
}