Class Name: SD
Functionality:
Initializes the TF card.
Function Prototype:
begin(cspin)
Parameter | Description |
---|---|
cspin | The chip select pin for the TF card (optional, defaults to the SPI's SS pin) |
Usage Example:
#include <M5Stack.h>
void setup() {
SD.begin();
}
Functionality:
Opens a specified file in the specified mode.
Function Prototype:
File open(const char *filepath, uint8_t mode);
Parameter | Description |
---|---|
filepath | File path |
mode | Open mode |
Usage 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() {
}