pdf-icon

Arduino 上手教程

StamPLC SDCard

StamPLC SD 案例程序

本案例中,StamPLC使用ESP32 Arduino SD库作为屏幕驱动, 参考下方案例即可实现简单的显示, 获取更多API内容可以参考arduino-esp32源码。
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include <Arduino.h>
#include <M5StamPLC.h>
#include <SD.h>
void setup()
{
delay(3000);
/* Enable SD card */
auto config = M5StamPLC.config();
config.enableSdCard = true;
M5StamPLC.config(config);
M5StamPLC.begin();
}
void loop()
{
static int count = 0;
// Write file
printf("\nSD card write test\n");
auto file = SD.open("/test.txt", FILE_WRITE, true);
if (file) {
file.printf("Hello, World! Count: %d\n", count);
file.close();
printf("SD card write success\n");
} else {
printf("Failed to open file\n");
}
// Read file
printf("\nSD card read test\n");
file = SD.open("/test.txt");
if (file) {
printf("SD card read success:\n");
while (file.available()) {
printf("%c", file.read());
}
} else {
printf("Failed to open file\n");
}
count++;
delay(1000);
}
On This Page