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?
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
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!
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.
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).....?
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: