ESP32 is unable to store more than 4 bytes in EEPROM

Hi,

I'm trying to store some values in the ESP32's EEPROM (which should be 512 bytes in size). However, I'm only able to store 4 values in there. I've simplified the code so just the part that matters is in there.

In detail, I can jsut store 4 bytes in the EEPROM (addresses 0-3); everything above 3 as the address is not written to the EEPROM. It always just reads the value 0.

The code is as follows:

#include <EEPROM.h>
void setup() {
  Serial.begin(115200);
  EEPROM.begin(1);
  
  EEPROM.write(3,244);
  EEPROM.write(4,255);
  EEPROM.commit();
  
  Serial.println();
  Serial.print("EEPROM value 3 is ");
  Serial.println(EEPROM.read(3));
  Serial.print("EEPROM value 4 is ");
  Serial.println(EEPROM.read(4));
}

void loop() {
  // put your main code here, to run repeatedly:

}

I've attached the serial monitor as an image. The log shows no errors.

Bastian2001:
EEPROM.begin(1);

The argument to EEPROM.begin() sets the size of the emulated EEPROM. You are only setting it to 1 byte, so it's surprising that you can even store 4 bytes. Increase that number and the problem should be solved.

Ouch, I thought this parameter was the size of one element in the EEPROM (so I thought setting it to 2 would allow me to save e.g. 16-bit integers in the EEPROM). But ok, increasing that value helped. Thanks

You're welcome. I'm glad to hear it's working now. Enjoy!
Per