Arduino Guide
Class Name: SD
Description:
Initializes the TF card.
Syntax:
begin(cspin)
Parameter | Description |
---|---|
cspin | The chip select pin for the TF card (optional, defaults to the SPI's SS pin) |
Example:
#include <M5Stack.h>
void setup() {
SD.begin();
}
Description:
Opens a specified file in the specified mode.
Syntax:
File open(const char *filepath, uint8_t mode);
Parameter | Description |
---|---|
filepath | File path |
mode | Open mode |
Example:
//Please create hello.txt in advance through a PC and copy it to the root directory of the TF card
#include <M5Stack.h>
void setup() {
M5.begin();
if (!SD.begin()) {
M5.Lcd.println("Card failed, or not present");
// Endlessly loop if the card cannot be initialized.
while (1);
}
Serial.println("TF card initialized.");
File f = SD.open("/hello.txt", FILE_READ);
if (f) {
M5.Lcd.print(f.read());
f.close();
} else {
M5.Lcd.println("open error hello.txt");
}
}
void loop() {
}