#include "FS.h"
#include "SD.h"
#include "SD_MMC.h"
void WriteFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
//unsigned long start_time = millis();
Serial.printf("write [%s]...\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (!file.write(buf, len)) {
Serial.println("Write failed");
return;
}
file.flush();
file.close();
Serial.printf("Write [%s] Complete", path);
}
void ReadFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
Serial.printf("read [%s]...\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
if (!file.read(buf, len)) {
Serial.println("Read failed");
return;
}
file.close();
Serial.printf("Read [%s] Complete: %s", path, buf);
}
void testIO(fs::FS &fs)
{
char buf[] = "hello world";
WriteFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
ReadFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("请插入内存卡");
delay(8000);
/* SD_MMC 4-bit Mode */
if (!SD_MMC.begin()) {
Serial.println("Card Mount Failed");
return;
}
testIO(SD_MMC);
SD_MMC.end(); // 取消SD挂载
}
void loop() {
}
#include "FS.h"
#include "SD.h"
#include "SD_MMC.h"
void WriteFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
//unsigned long start_time = millis();
Serial.printf("write [%s]...\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (!file.write(buf, len)) {
Serial.println("Write failed");
return;
}
file.flush();
file.close();
Serial.printf("Write [%s] Complete", path);
}
void ReadFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
Serial.printf("read [%s]...\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
if (!file.read(buf, len)) {
Serial.println("Read failed");
return;
}
file.close();
Serial.printf("Read [%s] Complete: %s", path, buf);
}
void testIO(fs::FS &fs)
{
char buf[] = "hello world";
WriteFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
ReadFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("请插入内存卡");
delay(8000);
/* SD_MMC 1-bit Mode */
if (!SD_MMC.begin("/cdcard", true)) {
Serial.println("Card Mount Failed");
return;
}
testIO(SD_MMC);
SD_MMC.end(); // 取消SD挂载
}
void loop() {
}
#include "FS.h"
#include "SD.h"
#include "SD_MMC.h"
void WriteFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
//unsigned long start_time = millis();
Serial.printf("write [%s]...\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (!file.write(buf, len)) {
Serial.println("Write failed");
return;
}
file.flush();
file.close();
Serial.printf("Write [%s] Complete", path);
}
void ReadFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
Serial.printf("read [%s]...\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
if (!file.read(buf, len)) {
Serial.println("Read failed");
return;
}
file.close();
Serial.printf("Read [%s] Complete: %s", path, buf);
}
void testIO(fs::FS &fs)
{
char buf[] = "hello world";
WriteFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
ReadFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("请插入内存卡");
delay(8000);
/* SD SPI Mode at HSPI */
SPIClass spi = SPIClass(HSPI);
spi.begin(14 /* SCK */, 12 /* MISO */, 13 /* MOSI */, 15 /* SS */);
if (!SD.begin(15 /* SS */, spi, 80000000)) {
Serial.println("Card Mount Failed");
return;
}
testIO(SD);
SD_MMC.end(); // 取消SD挂载
}
void loop() {
} 采用 32GB 闪迪 TF卡出现以下问题:
#include "FS.h"
#include "SD.h"
#include "SD_MMC.h"
void WriteFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
//unsigned long start_time = millis();
Serial.printf("write [%s]...\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (!file.write(buf, len)) {
Serial.println("Write failed");
return;
}
file.flush();
file.close();
Serial.printf("Write [%s] Complete", path);
}
void ReadFile(fs::FS &fs, const char *path, uint8_t *buf, int len)
{
Serial.printf("read [%s]...\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
if (!file.read(buf, len)) {
Serial.println("Read failed");
return;
}
file.close();
Serial.printf("Read [%s] Complete: %s", path, buf);
}
void testIO(fs::FS &fs)
{
char buf[] = "hello world";
WriteFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
ReadFile(fs, "/test.txt", (uint8_t *)buf, strlen(buf));
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("请插入内存卡");
delay(8000);
/* SD SPI Mode at VSPI */
SPIClass spi = SPIClass(HSPI);
spi.begin(18 /* SCK */, 19 /* MISO */, 23 /* MOSI */, 5 /* SS */);
if (!SD.begin(5 /* SS */, spi, 80000000)) {
Serial.println("Card Mount Failed");
return;
}
testIO(SD);
SD_MMC.end(); // 取消SD挂载
}
void loop() {
} 采用 32GB 闪迪 TF卡出现 VSPI 同样问题,换成 32GB Kingston TF 卡正常。
寄存器的功能是存储二进制代码,它是由具有存储功能的触发器组合起来构成的。一个触发器可以存储1位二进制代码,故存放n位二进制代码的寄存器,需用n个触发器来构成。
本节主要讲解舵机驱动类和用按键控制舵机。
本节主要讲解执行器件类型和用按键控制继电器。
本小节主要讲解红外接收和遥控器件,以及遥控操作LED。
本小节讲解模拟量传感器使用,旋转电位器,DHT11温湿度传感器和实现自定义传感器类。
本小节讲解Sensor类及派生类、数字量传感器使用和传感器的推荐交互流程。
本小节讲解ESP32内置触摸引脚的用法,
本小节主要介绍按键信号转换、Button类及派生类、和Button交互推荐流程。
本小节主要介绍Ws2812灯珠的使用、对父类进行扩展实现自定义功能,和指针向下强制转换的使用。
本小节主要介绍RGB三色LED的使用,以及多态的具体实现。
ESP32 Arduino Framework是专门针对ESP32开发板的Arduino应用开发框架,为用户开发IOT应用、HMI应用提供一致的开发体验。