pdf-icon

Arduino 上手教程

Basic/Fire/Gray/M5GO TF 卡

类名:SD

begin()

功能说明:

初始化 TF 卡

函数原型:

begin(cspin);
参数 描述
cspin TF 的片选引脚 (默认是 SPI 的 SS 引脚),可选

案例程序:

cpp
1 2 3 4 5
#include <M5Stack.h>
void setup() {
SD.begin();
}

open()

功能说明:

以指定模式打开指定文件

函数原型:

File open(const char *filepath, uint8_t mode);
参数 描述
filepath 文件路径
mode 打开模式

案例程序:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//请提前通过 PC 创建 hello.txt 并拷贝到 TF 卡根目录内
#include <M5Stack.h>
void setup() {
M5.begin();
if (!SD.begin()) {
M5.Lcd.println("Card failed, or not present");
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() {
}
On This Page