ESP32 with Arduino IDE and EEPROM.h library: values are not saved

Markovicz
Posts: 4
Joined: Thu Aug 20, 2020 5:32 pm

ESP32 with Arduino IDE and EEPROM.h library: values are not saved

Postby Markovicz » Sun Nov 08, 2020 10:02 pm

Hi Guys,

I've been trying the last couple of hours to get my code running with saving and reading EEPROM registers using Arduino IDE and the EEPROM.h library:
https://www.arduino.cc/en/Reference/EEPROM

I've followed a few blog entries about using ESP32 with EEPROM.h:
https://randomnerdtutorials.com/esp32-flash-memory/
https://www.electronics-lab.com/project ... a-storage/

I would like to go for data types larger than one byte, which is why I will use EEPROM.put and EEPROM.get instead of .write and .read in the following code example.

Please have a look at my minimum code example:

Code: Select all

// ******Required for Wakeup***************
#include "driver/rtc_io.h"
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  10

#include <EEPROM.h>
#define EEPROM_SIZE 100
int variable1 = 6;
int variable2 = 6;
int variable3 = 6;
int variable4 = 6;

void setup() {
Serial.println("Setup started: ");
Serial.begin(9600);
EEPROM.begin(EEPROM_SIZE);
delay(5000);
variable1 = EEPROM.get(0,variable1);
variable2 = EEPROM.get(1,variable2);
variable3 = EEPROM.get(2,variable3);
variable4 = EEPROM.get(3,variable4);
Serial.print("Variables in setup mode: "); Serial.print(variable1); Serial.print(variable2); Serial.print(variable3); Serial.println(variable4);
}

void loop() {
Serial.println("Loop started");
variable1 = 1;
variable2 = 2;
variable3 = 3;
variable4 = 4;
delay(5000);
EEPROM.put(0,variable1);
EEPROM.commit();
EEPROM.put(1,variable2);
EEPROM.commit();
EEPROM.put(2,variable3);
EEPROM.commit();
EEPROM.put(3,variable4);
EEPROM.commit();
variable1 = EEPROM.get(0,variable1);
variable2 = EEPROM.get(1,variable2);
variable3 = EEPROM.get(2,variable3);
variable4 = EEPROM.get(3,variable4);
Serial.print("Variables in loop mode: "); Serial.print(variable1); Serial.print(variable2); Serial.print(variable3); Serial.println(variable4);
Serial.println("now going to sleep");
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
Which shows the following output:
23:00:37.159 -> Loop started
23:00:42.160 -> Variables in loop mode: 6730598526291410274
23:00:42.195 -> now going to sleep
23:00:52.101 -> *!⸮zY⸮b⸮⸮o⸮De⸮S⸮!⸮Variables in setup mode: 6730598526291410274
23:00:57.260 -> Loop started
23:01:02.250 -> Variables in loop mode: 6730598526291410274
23:01:02.283 -> now going to sleep


So basically the values are nowhere stored, not even in the loop.
Thanks for your help!

Who is online

Users browsing this forum: No registered users and 67 guests