TF 卡

类名:SD

begin()

功能:

初始化 TF 卡

函数原型:

begin(cspin)

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

使用示例:

#include <M5Stack.h>

void setup() {
  SD.begin();
}

open()

功能:

以指定模式打开指定文件

函数原型:

File open(const char *filepath, uint8_t mode;

参数 描述
filepath 文件路径
mode 打开模式

使用示例:

//请提前通过 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