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 3 years have passed since last update.

ESP32のEEPROM機能で日本語を保存してみた

Posted at

EEPROMの日本語保存でちょっとだけ手間取ったのでメモ

#include <EEPROM.h>
int a = 0;

//値を入力する構造体作成
struct CONFIG {
  char camnm[37];//12文字入るサイズ 12バイト*3+1バイト
  char ch1nm[37];
  char ch2nm[37];   
};

void setup(){
  Serial.begin(9600);

  //保存されている設定値を読み取る
  EEPROM.begin(300);//サイズ指定
  CONFIG buf;
  EEPROM.get<CONFIG>(0, buf);

  //保存されている値を表示
  Serial.println( buf.camnm );
  Serial.println( buf.ch1nm );
  Serial.println( buf.ch2nm );
}

void loop() {
  if(a == 0){
    String strcamnm = "かめらの名前";
    String strch1nm = "チャンネル1";
    String strch2nm = "チャンネル2";

    strcamnm.toCharArray(buf.camnm,37);
    strch1nm.toCharArray(buf.ch1nm,37);
    strch2nm.toCharArray(buf.ch2nm,37);
  
    EEPROM.put<CONFIG>(0, buf);
    EEPROM.commit();
    a = 1;
  }

ちなみに全角文字は3バイトを使用するとのことで、最後に\nがつくため+1バイトが必要らしい。
「char camnm[37];//12文字入るサイズ 12バイト*3+1バイト」の部分。

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?