0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ESP32: フラッシュメモリーの使い方

Posted at

こちらのページを参考にしました。
ESP32-WROOM-32のFlashへファイルI/Oすると便利

プログラム

flash_memory.ino
// ---------------------------------------------------------------------
/*
	flash_memory.ino

						Aug/05/2024
*/
// ---------------------------------------------------------------------
#include "FS.h"
#include "SPIFFS.h"

#define FORMAT_SPIFFS_IF_FAILED true
// ---------------------------------------------------------------------
int count = 0;
void setup()
{
	// put your setup code here, to run once:

	Serial.begin(115200);

	delay(100);
	SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);	
	delay(100);
	Serial.println("*** start ***");
	delay(100);

	fs::FS fs = SPIFFS;
	File file = fs.open("/hello.txt", FILE_WRITE);
	file.print("*** Flash Memory ***\r\n");
	file.print("Aug/05/2024\r\n");
	file.print("*** テスト ***\r\n");
	file.print("*** end ***\r\n");
	delay(100);


	Serial.println("*** setup end ***");
}

// ---------------------------------------------------------------------
void loop() 
{
	Serial.println("Hello World! " + String(count));
	delay(1000);
	Serial.println("Good Morning! " + String(count));
	delay(1000);
	Serial.println("こんにちは " + String(count));
	Serial.println();
	delay(1000);

	fs::FS fs = SPIFFS;
	File file = fs.open("/hello.txt");
	while(file.available()){
	Serial.write(file.read());
	}

	delay(2000);
	count++;
}

// ---------------------------------------------------------------------

実行結果

$ cu -l /dev/ttyUSB0 -s 115200
Connected.
(省略)
*** start ***
*** setup end ***
Hello World! 0
Good Morning! 0
こんにちは 0

*** Flash Memory ***
Aug/05/2024
*** テスト ***
*** end ***
Hello World! 1
Good Morning! 1
こんにちは 1

*** Flash Memory ***
Aug/05/2024
*** テスト ***
*** end ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?