Arduino: use on ESP32 EEPROM (6)

Now we will share how to use EEPROM on board bpibit. Reading the data stored in the use of EEPROM.

EEPROM (Electrically Erasable Programmable read only memory ) refers to a charged erasable programmable read only memory. EEPROM can be used to cure without the use of some of the system files and data, such as to save the common SSID or Password, saved user name and password, user setting data such as save, more complex applications may be achieved.
The default size of 4096 bytes EEPROM objects, the user operates the addresses 0-4095.

Supporting Introduction

Authoring Tools: vscode + platformIO installation tutorial

Hardware: bpibit

The main function

  • EEPROM.begin(size): On EEPROM
parameter Features
size The maximum size for the address + 1 bytes to read and write data, in the range of 1 to 4096
  • EEPROM.write(addr, data): Write data to the storage space
parameter Features
addr Address storage space
data The actual writing of data
  • EEPROM.commit(): After each write address need to call this function

  • EEPROM.read(addr): Reading data from storage space

parameter Features
addr Address storage space

The main example

/*
该代码向 EEPROM 写入数据,然后再从 EEPROM 中读出来
*/
#include <EEPROM.h>

void setup() 
{
  Serial.begin(9600);
  Serial.println("Start write");

  EEPROM.begin(4096); //申请操作到地址4095(比如你只需要读写地址为100上的一个字节,该处也需输入参数101)
  for(int addr = 0; addr<4096; addr++)
  {
    int data = addr%256; //在该代码中等同于int data = addr;因为下面write方法是以字节为存储单位的
    EEPROM.write(addr, data); //写数据
  }
  EEPROM.commit(); //保存更改的数据。 在这里也可以用 EEPROM.end()

  Serial.println("End write");

  for(int addr = 0; addr<4096; addr++)
  {
    int data = EEPROM.read(addr); //读数据
    Serial.print(data);
    Serial.print(" ");
    delay(1);
    if((addr+1)%256 == 0) //每读取256字节数据换行
    {
      Serial.println("");
    }
  }
  Serial.println("End read");
}

void loop() 
{
}


Open the serial port assistant. Remember the serial port baud rate adjusted assistant 9600. Then press the reset button on the board to bpibit from the serial port to receive complete information on the assistant.

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43474408/article/details/90753348