ESP32 - SD Card

by DIYables in Circuits > Microcontrollers

10 Views, 0 Favorites, 0 Comments

ESP32 - SD Card

This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://esp32io.com/tutorials/esp32-sd-card

In this guide, we'll explore how to use a Micro SD Card with the ESP32. We'll delve into the following topics:

Supplies

What It Is

The Micro SD Card Module can interface with ESP32 and it can carry a Micro SD Card. In another word, the Micro SD Card Module is a bridge between ESP32 and Micro SD Card

Wiring

Micro SD Card Module includes 6 pins:

VCC pin: connect to the ESP32's 5V pin.

GND pin: connect this pin to the ESP32's GND.

MISO pin: (Master In Slave Out) connect this pin to the ESP32's MISO pin.

Code

esp32-sd-card.ino - the sketch from the tutorial, unchanged.

/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-sd-card
*/

#include <SD.h>

#define PIN_SPI_CS 5 // The ESP32 pin GPIO5

File myFile;

void setup() {
Serial.begin(9600);

if (!SD.begin(PIN_SPI_CS)) {
while (1) {
Serial.println(F("SD CARD FAILED, OR NOT PRESENT!"));
delay(1000);
}
}

Serial.println(F("SD CARD INITIALIZED."));

if (!SD.exists("/esp32.txt")) {
Serial.println(F("esp32.txt doesn't exist. Creating esp32.txt file..."));
// create a new file by opening a new file and immediately close it
myFile = SD.open("/esp32.txt", FILE_WRITE);
myFile.close();
}

// recheck if file is created or not
if (SD.exists("/esp32.txt"))
Serial.println(F("esp32.txt exists on SD Card."));
else
Serial.println(F("esp32.txt doesn't exist on SD Card."));
}

void loop() {
}

Full Tutorial

The complete tutorial, wiring diagram and code explanation: https://esp32io.com/tutorials/esp32-sd-card