ESP32学习笔记-挂载SPIFFS读写本地Flash

写在前面

原来,ESP32还有本地存储!

这么小的东西,有GPIO、UART、I2C,还有蓝牙和WIFI,简直不要太完美!

测试代码

//加载库
#include "SPIFFS.h" 
#include "FS.h"

#define FORMAT_SPIFFS_IF_FAILED true

void setup()
{
  //开启串口
  Serial.begin(115200);
 
  //挂载FPIFFS
  Mount();
 
  //路径
  String path = "/hello.txt";
  //内容
  String str = "hello world !";
  //写入(覆盖)
  writeTxt_APPEND(SPIFFS,path,str);
 
  //读取
  String txt =  readTxt(SPIFFS,path);
  Serial.println( txt );
 
}
 
void loop()
{
  
}
 
 
//挂载FPIFFS
void Mount()
{
  //开启SD卡
  if(SPIFFS.begin())
  {
    //打印成功
    Serial.println("Mount succeed");
  }
  else
  {
    //打印失败
    Serial.println("Mount Failed");
  }
}
 
//写入(FILE_WRITE)
void writeTxt(fs::FS &fs,String path,String str)
{
  //打开文件
  File myFile = fs.open(path, FILE_WRITE);  //FILE_WRITE 覆写
 
  //如果文件打开,则进行写入
  if (myFi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值