de:arduino:micro_sd_card

Micro SD-Kartenmodul

Micro SD-Kartenmodul

Das Modul (Micro SD Card Adapter) ist ein Micro SD-Kartenlesermodul. Das Modul verwendet einen SPI-Bus, um mit dem Arduino zu kommunizieren. Sobald das Modul angeschlossen ist, kann auf das Dateisystem der in das Modul eingelegten Karte vom Arduino aus zugegriffen, geschrieben und / oder gelesen werden. Typische Verwendung: Protokollierung von Messdaten.

Eine Zusammenfassung des Arduino SPI finden Sie hier: Arduino SPI.
Eine Zusammenfassung der SPI-Lösungen von Aduino finden Sie hier: Arduino SPI Kommunikation.

Die zur Verwendung im Modul vorgesehene SD-Karte muss im Voraus formatiert werden. Arduino verarbeitet auch die Formate FAT16 und FAT32, FAT16 wird jedoch trotzdem unterstützt. Für Dateinamen, die auf der SD-Karte verwendet werden, gilt das strengere 8.3-Format, d. H. Ein 8-stelliger Dateiname und eine 3-stellige Erweiterung.

Es ist wichtig, dass der Befehl file.write() erst auf die SD-Karte schreibt, wenn der vorherige Schreibvorgang entweder mit dem Befehl close() oder flush() geschlossen wurde. Der einfachste Weg, eine geöffnete Datei direkt nach dem Schreiben zu schließen, ist:

Software zeigen

Software zeigen

  File dataFile = SD.open(filename, FILE_WRITE);
    if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }

Es gibt verschiedene Arten von Kartenmodulen auf dem Markt, hier werde ich nur dieses beschreiben. Bei Bedarf werde ich die Dokumentation erweitern.

Die Kartenmodulanschlüsse sollten wie folgt mit dem Arduino UNO oder Mega verbunden werden:

Micro SDArduino UnoArduino Mega
CSpin 4pin 53
SCKpin 13pin 52
MOSIpin 11pin 51
MISOpin 12pin 50
VCC5V5V
GNDGNDGND

Micro SD Verdrahtung mit Arduino Uno

Eine Beschreibung des Micro SD-Kartenmoduls finden Sie auf der Arduino-Seite hier:

https://www.arduino.cc/en/Reference/SD

Die Bibliothek des Micro SD-Kartenmoduls kann hier heruntergeladen werden: https://github.com/greiman/SdFat

Es gibt auch eine große Auswahl an Beispielprogrammen zum Download: https://github.com/greiman/SdFat/tree/master/examples

SD card datalogger Software zeigen

SD card datalogger Software zeigen

/*
  SD card datalogger
 
  This example shows how to log data from three analog sensors
  to an SD card using the SD library.
 
  The circuit:
   analog sensors on analog ins 0, 1, and 2
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
 
  created  24 Nov 2010
  modified 9 Apr 2012
  by Tom Igoe
 
  This example code is in the public domain.
 
*/
 
#include <SPI.h>
#include <SD.h>
 
const int chipSelect = 4;
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
 
  Serial.print("Initializing SD card...");
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}
 
void loop() {
  // make a string for assembling the data to log:
  String dataString = "";
 
  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
 
  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}
  • de/arduino/micro_sd_card.txt
  • 2022/04/21 15:00
  • ()