Wednesday, June 20, 2018

The ESP8266 doesn't have EEPROM?

Unlike the Arduino AVR based controllers, the ESP8266 does not have a dedicated EEPROM. We can however use a bit of flash memory as a emulated EEPROM, and we can use the Arduino EEPROM library to do it. Using the Arduino Put and Get code samples as they are doesn't work. However a simple

EEPROM.begin(1024); // both the put and get code

before the

EEPROM.put(address, variable);
or
EEPROM.get(address, variable);


and a

EEPROM.commit(); // only on the put code

after it makes everything work.

In the linked code samples below, I'm saving 2 strings of text (wifi ssid and password) to the EEPROM in the put code, and retrieving them in the get code. If you put a slide switch in your project, and run the two pieces of code depending on the switch position, you can reset the credentials from a built in web form. I will cover that ability soon.

ESP8266 EEPROM "PUT"

ESP8266 EEPROM "GET"

Fore more info, see:
http://esp8266.github.io/Arduino/versions/2.0.0/doc/libraries.html#eeprom

https://www.baldengineer.com/arduino-eeprom-stores-any-datatype.html

2 comments:

  1. Why constrain yourself to the small size defined for eeprom in flash when you can use SPIFFS filesystem that also is stored in flash - this is much bigger and more versatile.

    ReplyDelete
  2. for just saving a ssid and password, I found the get and put easier to accomplish. I'll be doing a tutorial soon using SPIFFS and JSON for more intense data retrieval.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...