Hi all, I'm trying to connect an SD card module to an Arduino Nano ESP32, but I can't get the card to be recognized.
My connection scheme is as follows:
- Vcc --> 3.3V
- GND --> GND
- MISO --> D12
- MOSI --> D11
- SCK --> D13
- CS --> D10
I've already tried the following:
- The module works properly, as does the SD card, when connected to a standard Arduino Nano (ATmega328P).
- The voltage levels are correct.
- I've tried changing the pin assignments.
- I've tried setting the correct pin numbering in the Arduino IDE.
- I've tried connecting the SD module to another ESP32 board (ESP32-S3 Devkitc Wroom), but I got the same error.
It seems that either I'm not setting the pins correctly, or the libraries I'm using are not suitable for this configuration. Can anyone help?
Below you can find the latest sketch I used to test the connection:
#include <SPI.h>
#include <SD.h>
#define CS 21 // D10 corresponding to GPIO21
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
delay(2000);
Serial.println("Inizializing SD board...");
// Inizializza i pin SPI e il pin CS
SPI.begin(48, 47, 38, 21); // SCK = GPIO48, MISO = GPIO47, MOSI = GPIO38, CS = GPIO21
pinMode(CS, OUTPUT);
// Inizializza la scheda SD
if (!SD.begin(CS)) {
Serial.println("SD board inzialization failed!");
return;
}
Serial.println("SD board inizialized.");
// Apri il file per scrivere
File dataFile = SD.open("/LOG.csv", FILE_WRITE);
if (dataFile) {
dataFile.println("Hello test 1");
dataFile.close();
Serial.println("Data written into LOG.csv.");
} else {
Serial.println("Error while opening LOG.csv.");
}
}
void loop() {
}