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?
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 '20 at 19:49commit()
method, which is unnecessary on a true Arduino. Did you pass the correct size toEEPROM.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 '20 at 20:57