I have been trying to get information of an SD card using the ESP32-S2-Saola-1 board, ESP32-S2-WROVER and a microSD card adapter. Every configuration that I've tried has failed to initialize. Here's the wiring that I'm currently using:
CS to IO10
MOSI to IO11
SCK to IO12
MISO to IO13
Ground to Ground
VCC to 5V
I've tried a few different example programs that others have written, but couldn't find anything specific to the ESP32-S2 boards. Below is the code meant for an ESP32-WVROOM that I would like to use for this board.
/*
SD card test for esp32
This example shows how use the utility libraries
The circuit:
SD card attached to SPI bus as follows:
SS = 5;
MOSI = 23;
MISO = 19;
SCK = 18;
by Mischianti Renzo <https://www.mischianti.org>
https://www.mischianti.org
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
// WeMos D1 esp8266: D8 as standard
const int chipSelect = SS;
void printDirectory(File dir, int numTabs);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!SD.begin(SS)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.println();
Serial.print("Card type: ");
switch (SD.cardType()) {
case CARD_NONE:
Serial.println("NONE");
break;
case CARD_MMC:
Serial.println("MMC");
break;
case CARD_SD:
Serial.println("SD");
break;
case CARD_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// print the type and size of the first FAT-type volume
// uint32_t volumesize;
// Serial.print("Volume type is: FAT");
// Serial.println(SDFS.usefatType(), DEC);
Serial.print("Card size: ");
Serial.println((float)SD.cardSize()/1000);
Serial.print("Total bytes: ");
Serial.println(SD.totalBytes());
Serial.print("Used bytes: ");
Serial.println(SD.usedBytes());
File dir = SD.open("/");
printDirectory(dir, 0);
}
void loop(void) {
}
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.print(entry.size(), DEC);
time_t lw = entry.getLastWrite();
struct tm * tmstruct = localtime(&lw);
Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
}
entry.close();
}
}