#include <SD.h>
#include <SPI.h>
#include <Arduino.h>
#define SCK 36 //SCK on SPI3
#define MOSI 35 //MISO on SPI3
#define MISO 37 //MOSI on SPI3
#define SS 38
File root;
void setup() {
Serial.begin(115200);
SPI.begin(SCK, MISO, MOSI, SS);
Serial.print("Initializing SD card... ");
if (!SD.begin(SS)) {
Serial.println("Card initialization failed!");
while (true);
}
Serial.println("initialization done.");
Serial.println("Files in the card:");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}