I started working on a project that involves an ESP32. I’m using the Arduino platform to develop on the ESP32. This is a platform I have some familiarity with.

When I went to use the EEPROM to save some information, I just could not make it work. The information did not seem to register to the EEPROM and/or read back from the EEPROM.

The reason is because the EEPROM needs to be initialized when using an ESP32 board and not on Arduinos.

Here is the example from the Arduino website for standard Arduinos:

#include <EEPROM.h>

void setup() {
    Serial.begin(9600);
}

void loop() {
    int value = EEPROM.read(0);
    Serial.println(value);
    EEPROM.write(0, value + 1);
}

The Arduino does not require any setup for the EEPROM.

On ESP32 on the other hand, the EEPROM needs to be initialized and given a maximum size.

Also when writing, the EEPROM library needs to commit to actually write down the values.

Here is the same example updated for ESP32 support.

#include <EEPROM.h>

void setup() {
    Serial.begin(9600);

    // Needed on ESP32
    EEPROM.begin(1); // 1 is the size we use from the EEPROM
}

void loop() {
    int value = EEPROM.read(0);
    Serial.println(value);
    EEPROM.write(0, value + 1);
    EEPROM.commit(); // Also needed when writing to the EEPROM on ESP32
}

I wrote this post for my future self. Because something is Arduino compatible does not mean it is 100% the same thing.