//legend :)
//DO -> 19 = MISO
//SCK -> 18 = CLOCK
//DI -> 23 = MISO
//CS = Chip select -> ?
//-----------------------using SdFat-------------------
#include "SdFat.h"
#define SPI_SPEED SD_SCK_MHZ(4)
#define CS_PIN 32
SdFat sd;
void setup() {
Serial.begin(115200);
if (!sd.begin(CS_PIN, SPI_SPEED)) {
if (sd.card()->errorCode()) {
Serial.println("SD initialization failed.");
} else if (sd.vol()->fatType() == 0) {
Serial.println("Can't find a valid FAT16/FAT32 partition.");
} else {
Serial.println("Can't determine error type");
}
return;
}
Serial.println("Files on card:");
Serial.println(" Size Name");
//recursively display all files in directory and subdirectories with their size - included in FAT library
sd.ls(LS_R | LS_SIZE);
}
void loop() {
}
//---------------------------------------------------
//-----------------------using SD library--------------------
// #include <SD.h>
// #define MAX_FILENAME_SIZE 50
// #define CS_PIN 32
// File root;
// void setup() {
// Serial.begin(115200);
// //initializing SD card
// if (!SD.begin(CS_PIN)) {
// Serial.println("Card initialization failed!");
// while (true);
// }
// Serial.println("initialization done. Files in the card:");
// root = SD.open("/");
// //iterate through directories and files
// printDirectory(root, 0);
// // Example of reading file from the card:
// }
// void loop() {
// delay(100);
// // nothing happens after setup finishes.
// }
// 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');
// }
// //getting name of file to prepare txt check
// Serial.print(entry.name());
// char filename[MAX_FILENAME_SIZE];
// strcpy(filename,entry.name());
// if (entry.isDirectory()) {
// Serial.println("/");
// printDirectory(entry, numTabs + 1);
// } else {
// // files have sizes, directories do not
// Serial.print("\t\t");
// Serial.print(entry.size(), DEC);
// if(isTextFile(filename)){
// Serial.print("\t\t");
// Serial.println("this is a text file");
// readTextFile(entry, filename);
// }else{
// Serial.println("");
// }
// }
// entry.close();
// }
// }
// void readTextFile(File textFile, char* filename){
// if (textFile) {
// Serial.println(filename);
// while (textFile.available()) {
// Serial.write(textFile.read());
// }
// textFile.close();
// String result = String(filename);
// Serial.println("Finished printing " + result);
// } else {
// Serial.println("error opening file!");
// }
// }
// bool isTextFile(char* filename) {
// int8_t len = strlen(filename);
// bool result;
// if ( strstr(strlwr(filename + (len - 4)), ".txt")
// // and anything else you want
// ) {
// result = true;
// } else {
// result = false;
// }
// return result;
// }
//--------------------------------------------------