0

In my project i am using nodemcu board.It is clone of Adafruit's huzzah. Last days i faced a problem about eeprom. 1- I have some data and i have to save this datas on eeprom. 2- Data types are various(String, float, etc). 3- I can easily read and write data to eeprom. Easily clear too. But sometimes my eeprom crashing and all stored data deleting. I faced this problem when i upload new program to card. I am using EEPROM.h library.

Here is the my eeprom write example :

boolean WriteEPPass(String pass)
     {      
       for (int i = 0; i < pass.length(); ++i) 
       {
         EEPROM.write(32 + i, pass[i]);
       }
       EEPROM.commit();
       return true;
 }

And eeprom read example :

String ReadEP(int startIndex,int length)
     {
       String content;
         for (int i = startIndex; i < length; ++i) {
           content += char(EEPROM.read(i));
         }
       return content;
     }

And i am using this methods for float variables:

boolean WriteEPRegulator(float_t regulator)
    {

         EEPROM.put(203,regulator);
         #ifdef DEBUG
         Serial.print("REGULATORDATALENGTH: ");
     //  Serial.println(regulator.length());
         #endif
         EEPROM.commit();
         return true;
}

As i said on top, i can easy do R/W process. But sometimes for instance when i uploading code or change power supply from usb to battery my stored datas are deleting.

Is there any proper suggestion and fix about this issue?

  • I think, the NodeMCU does not have an EEPROM. With the EEPROM class you are effectively writing to the flash memory, which can get overwritten by programming. Though I don't know how to best deal with this – chrisl Jun 8 at 19:49
  • If nodemcu does not have an eeprom, all stored data deleting on every upload i think. But its not happens every upload. – Dogan Cignakli Jun 8 at 19:51
  • @chrisl is correct. NodeMCU is an ESP8266 - it does not have EPROM. It does have flash memory. The EEPROM module writes to reserved locations in flash. That's why it's important to call the commit() method, which is unnecessary on a true Arduino. Did you pass the correct size to EEPROM.begin()? You need to pass it a large enough number to store everything. And while this is probably a software error, the flash memory only has a life of 10,000 to 100,000 cycles. If you write to it very frequently it's possible you've worn it out. – romkey Jun 8 at 20:57
  • I am setting eeprom with 512 and it is enough now. And i am calling commit on every write process. I am frequently write sth to the eeprom – Dogan Cignakli Jun 8 at 21:03
  • 1
    use SPIFFS instead. it's file interface is easy to organize and integrate, you can store a lot more, and it's wear-leveled, so if you only use 1% of your space, it (theoretically) lasts 100X longer than a fixed address. – dandavis Jun 10 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.