Guys, I made a program for the Arduino in which it reads a value from the eeprom and with this value I make a calculation, this value is assigned by a nextion ihm and whenever it changes in the eeprom.
It very rarely happens that when the Arduino is powered, this eeprom value that was previously at 100, 50 or any other value out of nowhere is displayed with 255. It is as if the eeprom was turned off.
If there is Arduino/Nextion communication involved in the process of assigning a value to the variable to be stored, a failure in the reading/writing could lead to a bad value in the arduino eeprom. How do you confirm that the value from the Nextion is correct?
The value is read from the eeprom and displayed on the display and I have a button to increase and decrease the value, I always use the value within the range of 0 to 100 and every time the value is changed it is written to the eeprom. What is strange and rarely happens is that sometimes the value shown on the display is 255 (FF).
What Arduino do you have? That is a common problem with the ESP Arduinos as the EEPROM is non existent but simulated in RAM and saved in flash. You need to commit the EEPROM to flash with this statement"
EEPROM.commit();, for more information check ESP32 Flash Memory - Save Permanent Data | Random Nerd Tutorials
I had the same issue you described and in my case the cause was the corruption of the EEPROM during power cycling.
The solution was to enable brown-out detection by changing the fuses of the MCU, this ensures the CPU turns off when the power goes too low to prevent erratic execution of code.