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?

arduino1.8を使ってPCからESP32のSPIFFS領域にファイルを送信する

Last updated at Posted at 2025-05-18

今回は、ESP32のSPIFFS領域にファイルを保存する必要があったので記録として残します。

1、開発環境

arduino1.8.19

2、方法

1、arduino1.8.19をインストール。以下のURLから
https://www.arduino.cc/en/software/
image.png

2、今回のボードの設定は以下です。
image.png

3、以下のサイトからESP32FS-1.1.zipをダウンロードして、解凍後
C:\Users*****\OneDrive\ドキュメント\Arduino\toolsフォルダに保存(toolsフォルダは作成する必要あり)
https://github.com/me-no-dev/arduino-esp32fs-plugin/releases/tag/1.1
(ESP32FSごと保存)

4、arduinoIDEを起動してESP32 Sketch Data Uploadが表示されればOK
image.png

5、プログラムと同じフォルダにdataフォルダを作成して、そのフォルダに書き込みたいファイルを保存。
  その後、ESP32 Sketch Data Uploadを実行したら確認できます。
 今回は、config.txtファイルを作成して、中身は「hello」と書き込みをしています。

6、以下のプログラムを作成して動作確認して下さい。()

#include "FS.h"
#include <SPIFFS.h>

void setup() {
    SPIFFS.format(); // 初回フォーマット時のみ有効にする(次回書き込みからは無効にする)
    Serial.begin(115200);
    if (!SPIFFS.begin(true)) {
        Serial.println("SPIFFSのマウントに失敗しました。");
        return;
    }

}

void loop() {
    delay(2000);
    File file = SPIFFS.open("/config.txt", "r");
    if (!file) {
        Serial.println("ファイルを開けませんでした。");
        return;
    }

    Serial.print("config.txtの内容:");
    while(file.available()){  // ファイルのデータ分繰り返す
      char c = file.read(); // ファイルから1バイトずつデータを読み取り
      Serial.print(c);      // 液晶へ表示
    }
    Serial.println();
    file.close();
}

7、2秒間隔でhelloが表示されればOKです。
image.png

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?