Hi,
Start your code here /* Testing EEPROMClas ESP32 Flash memory in a multiple user-defined EEPROM class objects. Created for arduino-esp32 on 25 Dec, 2017 by Elochukwu Ifediora (fedy0) converted to nvs by lbernstone - 06/22/2019EEPROM.update() on ESP32https://github.com/espressif/arduino-esp32/tree/master/libraries/Preferences putString(const char* key, const String value) */ #include "EEPROM.h" #include "Preferences.h" #define uS_TO_S_FACTOR 1000000ULL RTC_DATA_ATTR uint32_t age = 0; RTC_DATA_ATTR uint32_t check2 = 0; RTC_DATA_ATTR uint32_t check3 = 0; EEPROMClass NAMES("eeprom0", 0x500); EEPROMClass HEIGHT("eeprom1", 0x200); EEPROMClass AGE("eeprom2", 0x100); void setup() { Serial.begin(115200); Serial.println(EEPROM.read(0x100)); Serial.println(EEPROM.read(0)); printf("\n-----------------"); // Instantiate eeprom objects with parameter/argument names and sizes if (!NAMES.begin(NAMES.length())) { Serial.println("Failed to initialise NAMES"); Serial.println("Restarting..."); ESP.restart(); } if (!HEIGHT.begin(HEIGHT.length())) { Serial.println("Failed to initialise HEIGHT"); Serial.println("Restarting..."); delay(1000); ESP.restart(); } if (!AGE.begin(AGE.length())) { Serial.println("Failed to initialise AGE"); Serial.println("Restarting..."); delay(1000); ESP.restart(); } AGE.get(0, age); printf("\nrestarted age = %d\n", age); Serial.println(check2); if ((check2 < 1)) { const char* name = "2020-09-16 | 17:04:28 Humidité du sol: 114.00% Température du sol: 14.87°C Température: 26.40°C Humidité: 65.70% Ressentie: 27.66°C Rosé 19.48°C"; double height = 5.8; uint32_t age = 47; check2 += 1; Serial.print("In check2: "); Serial.println(check2); Serial.println("----------------- WRITE -------------------\n"); NAMES.put(0, name); HEIGHT.put(0, height); AGE.put(0, 47); // Write: Variables ---> EEPROM stores Serial.print("name: "); Serial.println(name); Serial.print("height: "); Serial.println(height); Serial.print("age: "); Serial.println(age); Serial.println("----------------- CLEAR -------------------\n"); // Clear variables Serial.printf("name: %s", name); name = '\0'; Serial.println(name); height = 0; age = 0; Serial.print("name: "); Serial.println(name); Serial.print("height: "); Serial.println(height); Serial.print("age: "); Serial.println(age); Serial.println("----------------- READ -------------------\n"); // Read: Variables <--- EEPROM stores NAMES.get(0, name); HEIGHT.get(0, height); AGE.get(0, age); Serial.print("name: "); Serial.println( name); Serial.print("height: "); Serial.println(height); Serial.print("age: "); Serial.println(age); uint32_t age3 = 47; //AGE.put(0, age3); AGE.put(0, 47); Serial.println("\n------------ Going to sleep. --------------"); delay(1000); esp_sleep_enable_timer_wakeup(30 * uS_TO_S_FACTOR); esp_deep_sleep_start(); //ESP.restart(); } if (check2 > 0) { Serial.println("\nIn else after sleep"); const char rname[24] = {}; NAMES.get(0, rname[0]); double height2; HEIGHT.get(0, height2); uint32_t age2; AGE.get(0, age2); Serial.print("name: "); Serial.println( rname); Serial.print("height: "); Serial.println(height2); Serial.print("age2: "); Serial.println(age2); check3 += 1; } delay(20000); if (check3 < 2) { Serial.println("\n----------- ESP.restart() ---------------"); ESP.restart(); } Serial.println("\n-------------- Done!"); } void loop() { delay(0xFFFFFFFF); }
Regard
JPDaviau
6 Answers
After restart or deep_sleep the EEPROM memories are not readable, we cant recover the data.
After looking at this the EEPROM library is deprecated in favor of the Preferences library.
I tried the example at https://github.com/espressif/arduino-esp32/blob/master/libraries/Preferences/examples/StartCounter/StartCounter.ino and it worked perfectly.
My understanding is that ESP32 does not have an EEPROM and the Preferences library is just a wrapper around Flash memory to emulate an EEPROM.
Hi.
As Steve suggested, use the preferences library instead.
Then, let us know if it solved your problem.
Regards,
Sara