Arduino module wemos mini esp8266 eeprom
ESP8266, we can use the EEPROM.h library, very similar to the one for Arduino with some differences. Before using the function, we have to initialize the size of the memory with begin() and the update function does not exist but the write function does something similar.
begin() to initialize the memory size
put() to write
get() to read
commit() to validate changes
Other functions of the library can be used depending on the use you have of the EEPROM.
//Libraries
#include <EEPROM.h>//https://github.com/esp8266/Arduino/blob/master/libraries/EEPROM/EEPROM.h
//Constants
#define EEPROM_SIZE 12
void setup() {
//Init Serial USB
Serial.begin(115200);
Serial.println(F("Initialize System"));
//Init EEPROM
EEPROM.begin(EEPROM_SIZE);
//Write data into eeprom
int address = 0;
int boardId = 18;
EEPROM.put(address, boardId);
address += sizeof(boardId); //update address value
float param = 26.5;
EEPROM.put(address, param);
EEPROM.commit();
//Read data from eeprom
address = 0;
int readId;
EEPROM.get(address, readId);
Serial.print("Read Id = ");
Serial.println(readId);
address += sizeof(readId); //update address value
float readParam;
EEPROM.get(address, readParam); //readParam=EEPROM.readFloat(address);
Serial.print("Read param = ");
Serial.println(readParam);
EEPROM.end();
}
void loop() {}
Result
Comments
Post a Comment