Search code examples
arduinoarduino-esp8266eeprom

Why is the EEPROM of my ESP8266 not working?


I need to get some values saved into eeprom on my esp 8266, but it's not working. I get the Error "ERROR! EEPROM commit failed" when i try to EEPROM.commit() some writes. I tested it with my own code, but it also doesn't even work with the examples from the EEPROM library. I have multiple ESP8266MOD and tested with some of them, but no one worked. Anybody got an idea?

If you need additional Infos ill tell you


Solution

  • As we discussed in the comments, it is not working because ESP8266 do not have EEPROM and your option is to use Flash to emulate the EEPROM.

    I have not done a thorough research as I am not using ESP8266 on regular basis but did try the ESP_EEPROM library and it seem to be working well, here's the code I just tested:

    #include <ESP_EEPROM.h>
    
    void setup() {
      Serial.begin(115200);
      while(!Serial);
      EEPROM.begin(16); // looks like 16 bytes is the minimum
      EEPROM.put(0, 1234); // first parameter sets the position in the buffer, second the value
      boolean res = EEPROM.commit();
      Serial.println(res); // should print 1 (true) if commit worked as expected
      int myVar;
      EEPROM.get(0, myVar);
      Serial.println(myVar);
    }
    
    
    void loop() {
    }