Skip to content

Instantly share code, notes, and snippets.

@mobizt
Created April 14, 2019 08:18
Show Gist options
  • Save mobizt/0f857733b06d040be38aa6fd5e8242b4 to your computer and use it in GitHub Desktop.
Save mobizt/0f857733b06d040be38aa6fd5e8242b4 to your computer and use it in GitHub Desktop.
TTGO T8 V1.8 micro SD Card Test
//T8 V1.8 ESP32-WROVER 4MB PSRAM micro SD Test
#include <SD.h>
File dir;
void setup()
{
Serial.begin(115200);
//Built in micro SD card slot
SPI.begin(14, 2, 15, 13); //SCK, MISO, MOSI,SS
SD.begin(13, SPI);
dir = SD.open("/");
printDirectory(dir, 0);
//dir = SD.open("/");
// deleteFiles(dir);
}
void loop()
{
}
void deleteFiles(File dir) {
while (true) {
File entry = dir.openNextFile();
if (! entry) break;
if (entry.isDirectory()) {
deleteFiles(entry);
SD.rmdir(entry.name());
} else {
SD.remove(entry.name());
}
entry.close();
}
}
void printDirectory(File dir, int depth) {
while (true) {
File entry = dir.openNextFile();
if (! entry)
break;
for (uint8_t i = 0; i < depth; i++)
Serial.print("| ");
std::string name = entry.name();
if (entry.isDirectory()) {
Serial.print("+----" + String(name.substr(name.find_last_of("/\\") + 1).c_str()) + "\r\n");
printDirectory(entry, depth + 1);
} else {
Serial.print("+--" + String(name.substr(name.find_last_of("/\\") + 1).c_str()));
Serial.print("\t\t\t(");
Serial.print(entry.size(), DEC);
Serial.println(")");
}
entry.close();
}
}
void createDirs(std::string dirs) {
std::string dir = "";
int count = 0;
for (int i = 0; i < dirs.length(); i++) {
dir.append(1, dirs[i]);
count++;
if (dirs[i] == '/') {
if (dir.length() > 0)
SD.mkdir(dir.substr(0, dir.length() - 1).c_str());
count = 0;
}
}
if (count > 0)
SD.mkdir(dir.c_str());
}
@bartwybouw
Copy link

Thank you so much for sharing this. After days of testing and searching I found your code.
I'm using a TTG T-SIM7070G module and could not get the SD-card to work, seems the simple bit EVERYONE is missing is the second parameter "SPI" in SD.begin(13, SPI).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment