Παραγγελία έως τις 14:00 τις εργάσιμες = αποστολή την ίδια ημέρα 30 ημέρες δικαίωμα υπαναχώρησης Εγγύηση 1 έτους
← Πίσω στην επισκόπηση

Διάγραμμα σύνδεσης και παράδειγμα κώδικα

Έτσι συνδέεις το Μονάδα κάρτας Micro SD 3.3V για ESP32 | ESP8266 σε ένα Arduino UNO ή ESP32, με ένα παράδειγμα sketch που μπορείς να ανεβάσεις αμέσως.

Επίδειξη ανάγνωσης και εγγραφής κάρτας MicroSD

Αυτό το έργο δείχνει πώς να γράφετε κείμενο σε μια κάρτα microSD και να το διαβάζετε ξανά μέσω SPI. Ένας 4-channel logic level shifter μετατρέπει με ασφάλεια τα σήματα λογικής 5V του Arduino Uno σε 3.3V για το module κάρτας microSD. Ανοίξτε το Serial Monitor στα 115200 baud για να δείτε την κατάσταση αρχικοποίησης και τα περιεχόμενα του αρχείου.

Διάγραμμα σύνδεσης: Μονάδα κάρτας Micro SD 3.3V για ESP32 | ESP8266 σε ένα Arduino UNO
Διάγραμμα σύνδεσης · Κάνε κλικ για μεγέθυνση
Πίνακας σύνδεσης: Μονάδα κάρτας Micro SD 3.3V για ESP32 | ESP8266 σε ένα Arduino UNO
Πίνακας σύνδεσης · Κάνε κλικ για μεγέθυνση
MicroSD_Card_Read_and_Write_Demo.ino · μεταγλωττισμένο και δοκιμασμένο
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : MicroSD Card Read and Write Demo
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Micro SD Card Adapter Module 3.3V
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  Serial.println(F("Initializing SD card..."));

  if (!SD.begin(chipSelect)) {
    Serial.println(F("Initialization failed! Check connections & SD card."));
    return;
  }
  Serial.println(F("Initialization done."));

  // Write to file
  File myFile = SD.open("demo.txt", FILE_WRITE);
  if (myFile) {
    Serial.println(F("Writing to demo.txt..."));
    myFile.println(F("MicroSD card read/write test successful!"));
    myFile.close();
    Serial.println(F("Done writing."));
  } else {
    Serial.println(F("Error opening demo.txt for writing."));
  }

  // Read from file
  myFile = SD.open("demo.txt");
  if (myFile) {
    Serial.println(F("Contents of demo.txt:"));
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    myFile.close();
  } else {
    Serial.println(F("Error opening demo.txt for reading."));
  }
}

void loop() {
  // Idle
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Ανάγνωση και εγγραφή κάρτας MicroSD με ESP32

Αυτό το παράδειγμα δείχνει πώς να συνδέσετε ένα module κάρτας MicroSD 3.3V με το ESP32 χρησιμοποιώντας το προεπιλεγμένο hardware SPI bus (VSPI). Το sketch αρχικοποιεί την κάρτα SD, γράφει ένα δοκιμαστικό μήνυμα σε ένα αρχείο και το διαβάζει ξανά για να εμφανιστεί στο Serial Monitor.

Διάγραμμα σύνδεσης: Μονάδα κάρτας Micro SD 3.3V για ESP32 | ESP8266 σε ένα ESP32 DevKit V1
Διάγραμμα σύνδεσης · Κάνε κλικ για μεγέθυνση
Πίνακας σύνδεσης: Μονάδα κάρτας Micro SD 3.3V για ESP32 | ESP8266 σε ένα ESP32 DevKit V1
Πίνακας σύνδεσης · Κάνε κλικ για μεγέθυνση
MicroSD_Card_Read_and_Write_with_ESP32.ino · μεταγλωττισμένο και δοκιμασμένο
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : MicroSD Card Read and Write with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Micro SD Card Adapter Module 3.3V
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include "FS.h"
#include "SD.h"
#include "SPI.h"

const int chipSelect = 5;

void setup() {
  Serial.begin(115200);
  while (!Serial) { delay(10); }

  Serial.println("\n--- MicroSD Card Demo ---");

  // Initialize SD card on default VSPI pins (CS = GPIO 5)
  if (!SD.begin(chipSelect)) {
    Serial.println("Card Mount Failed! Check wiring and make sure card is FAT32 formatted.");
    return;
  }

  uint8_t cardType = SD.cardType();
  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached.");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);

  // Write to a test file
  Serial.println("Writing to test.txt...");
  File file = SD.open("/test.txt", FILE_WRITE);
  if (file) {
    file.println("Hello from ESP32!");
    file.println("MicroSD read/write test successful.");
    file.close();
    Serial.println("Write complete.");
  } else {
    Serial.println("Failed to open file for writing.");
    return;
  }

  // Read back the test file
  Serial.println("Reading from test.txt:");
  file = SD.open("/test.txt");
  if (file) {
    while (file.available()) {
      Serial.write(file.read());
    }
    file.close();
  } else {
    Serial.println("Failed to open file for reading.");
  }
}

void loop() {
  // Nothing to repeat in this test
  delay(1000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Πρόσφατα προβεβλημένα

Θήκη μπαταριών 8x AA (Back-To-Back 12V)

Θήκη μπαταριών 8x AA (Back-To-Back 12V)

€ 1,70