• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

EEPROM.update() on ESP32

Q&A Forum › Category: ESP32 › EEPROM.update() on ESP32
0 Vote Up Vote Down
Robert Gillespie asked 6 years ago

I’ve just finished the Flash read and write for the EEPROM on the ESP 32 from the video course from RUI.  I did go to the bit about the Arduino and it described that when you use the EEPROM.update and the value has not changed then the write does not take place and the number of times that the write is usable is not reduced on the Arduino.

Is this the same for the ESP 32?

Question Tags: EEPROM.update()
11 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Robert.

Contrary to the Arduino, the ESP32 doesn’t have an EEPROM.update() function.

However, the good news is that the EEPROM.write() on the ESP32 has the same properties of update. It only writes to EEPROM if we want to write something different.

Regards,
Sara

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

Hi,

Where can we get all of the EEPROM  commands and functions?

JPD

0 Vote Up Vote Down
Steph answered 5 years ago

https://github.com/espressif/arduino-esp32/blob/master/libraries/EEPROM/src/EEPROM.h

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

Hi,

I have download the EEPROM library you referred. I have a strange output here:

name: k@?⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮”(T⸮

and  what is the use of the delay?

Regards.

JPD

/*
ESP32 eeprom_class example with EEPROM library
This simple example demonstrates using EEPROM library to store different data in
ESP32 Flash memory in a multiple user-defined EEPROM class objects.

Created for arduino-esp32 on 25 Dec, 2017
by Elochukwu Ifediora (fedy0)
converted to nvs by lbernstone - 06/22/2019
*/
#include "EEPROM.h"
// Instantiate eeprom objects with parameter/argument names and sizes
EEPROMClass NAMES("eeprom0", 0x500);
EEPROMClass HEIGHT("eeprom1", 0x200);
EEPROMClass AGE("eeprom2", 0x100);
void setup() {
Serial.begin(115200);
Serial.println("Testing EEPROMClass\n");
if (!NAMES.begin(NAMES.length())) {
Serial.println("Failed to initialise NAMES");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
if (!HEIGHT.begin(HEIGHT.length())) {
Serial.println("Failed to initialise HEIGHT");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
if (!AGE.begin(AGE.length())) {
Serial.println("Failed to initialise AGE");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
const char* name = "Teo Swee Ann";
char rname[32];
double height = 5.8;
uint32_t age = 47;
// Write: Variables ---> EEPROM stores
NAMES.put(0, name);
HEIGHT.put(0, height);
AGE.put(0, age);
Serial.print("name: "); Serial.println(name);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age);
Serial.println("------------------------------------\n");
// Clear variables
name = '\0';
height = 0;
age = 0;
Serial.print("name: "); Serial.println(name);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age);
Serial.println("------------------------------------\n");
// Read: Variables <--- EEPROM stores
NAMES.get(0, rname);
HEIGHT.get(0, height);
AGE.get(0, age);
Serial.print("name: "); Serial.println(rname);
Serial.print("height: "); Serial.println(height);
Serial.print("age: "); Serial.println(age);

Serial.println("Done!");
}
void loop() {
delay(0xFFFFFFFF);
}

Start your code here

Testing EEPROMClass
name: Teo Swee Ann
height: 5.80
age: 47
————————————
name:
height: 0.00
age: 0
————————————
name: k@?⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮”(T⸮
height: 5.80
age: 47
Done!

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

That’s because they are not reading the correct thing on EEPROM.
They are reading rname, when they should read name:
replace this

NAMES.get(0, rname);

with this

NAMES.get(0, name);

Then, replace this:

Serial.print(“name: “); Serial.println(rname);

With this:

Serial.print(“name: “); Serial.println(name);

This should solve the issue.
 

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

Thank , it does work
 
But if  after printing done I code 

Start your code here
for (int i = 0; i < EEPROM_SIZE; i++)
{
Serial.print(byte(EEPROM.read(i)));
Serial.print(" ");
}


I get only 0 (zeros).....?
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

That’s probably because those variables are not being saved on these addresses.

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

The EEPROM of ESP32  wroom  has more than 512 bytes of flash memory?

1 Vote Up Vote Down
Steph answered 5 years ago

Hi,

Looking at the EEPROM library embedded in the Arduino core for the ESP32, I just noticed that this library is deprecated:

EEPROM is deprecated. For new applications on ESP32, use Preferences. EEPROM is provided for backwards compatibility with existing Arduino applications. EEPROM is implemented using a single blob within NVS, so it is a container within a container. As such, it is not going to be a high performance storage method. Preferences will directly use nvs, and store each entry as a single object therein.

It is better to use the Preferences library.
Here’s a basic example of use:

StartCounter.ino

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

Thanks again.

0 Vote Up Vote Down
Jean Pierre Daviau answered 5 years ago

Hi.
 
EEPROM.begin(EEPROM_SIZE); //to make it work

for (int i = 0; i < EEPROM_SIZE; i++)
{
Serial.print(byte(EEPROM.read(i)));
Serial.print(" ");
}

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.