text: I’ve been trying to create a “reboot” function for my project, whereby changing a flag will cause EEPROM to reset itself to a default set of values upon next upload. I have managed to get it working, though there is some strange behavior I’ve had to work around;
  #include <EEPROM.h> // Memory control void setup() { Serial.begin(74880); while (!Serial) delay(10); Serial.setTimeout(250); uint8_t MEM_Reboot = 6; // Change to reboot EEPROM. Serial.println("MEM_Reboot says " + (String)MEM_Reboot); uint8_t MEM_Pulled = EEPROM.read(0); Serial.println("Byte 0 says " + (String)MEM_Pulled); delay(1000); // Wait a second. if (MEM_Reboot != MEM_Pulled) // Rebooting EEPROM? { Serial.println("Reboot request granted."); EEPROM.write(0, MEM_Reboot); // EEPROM Rebooting. // Do some stuff to EEPRPOM } } void loop() { }
  This code will not work without the imposed 1 second delay right before the if-statement; without this delay MEM_Reboot will read the same as MEM_Pulled regardless of having changed the number before upload, asif EEPROM.write() jumped the line and executed before the code had a chance to execute EEPROM.read(0). It seems the arduino, or the library, does not like having to read and write in quick succession?
  Is this behavior expected?
  I am using a Wemos Mega, and Arduino IDE 1.8.13