Why can’t you use
You can also choose to save the value of your variable in Flash memory with the Preferences library (EEPROM is deprecated. It is provided on ESP32 for backwards compatibility with existing Arduino applications).
Using RTC_DATA_ATTR gives an error during compile: “section attribute cannot be specified for local variables”.
I am trying to learn how to use the EEPROM but I think the following line (used after Deep Sleep) is no good: waterWeight = EEPROM.read(8). The variable was stored as EEPROM.write(8, waterWeight) before Deep Sleep.
long bucketWeight_new = 0;
long bucketWeight_old = 0;
#define EEPROM_SIZE 8
bucketWeight_new = 10.1;
bucketWeight_old = EEPROM.read(8); //assign 10.1 to old
Serial.print(“bucketWeight_old = “); Serial.println(bucketWeight_old);
//Serial print statement is not executed
I don’t think there is any problem saving variables using EEPROM and deep sleep.
Doesn’t it work?
Also, it is weird that the RTC_DATA_ATTR is not working.
You must have declared your variable as a local variable.
However, a variable that is intended to be hosted in RTC memory must be global.
@Sandra… Looks like there’s a rendering bug in the HTML code since Ron’s last answer… a bit like if a <pre> tag or a <code> tag wasn’t closed properly…
You have the answer! I did not know I had to declare the variable using RTC_DATA_ATTR (variable name)=0 before Setup. It makes sense now. Hopefully this will solve my problem. Thank you very much for your help!!
No more need to bother with the EEPROM library (although it’s deprecated as I told you before).
Thank you all for your contributions.
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.