# Problem Using the EEPROMEX library

**URL:** <https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451>\
**Category:** 3rd Party Boards\
**Created:** [September 23, 2023, 2:41pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451 "2023-09-23T14:41:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 2:41pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/1 "2023-09-23T14:41:59Z")

</div>

Hello friends, I have written a sketch in which the eepromex library is used. The problem I have is that I wanted to write a command that would erase the entire internal eeprom memory. Can anyone guide me?

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [September 23, 2023, 3:00pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/2 "2023-09-23T15:00:59Z")

</div>

[EEPROM Clear | Arduino](https://wiki-content.arduino.cc/en/Tutorial/LibraryExamples/EEPROMClear)

Regards

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 23, 2023, 3:01pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/3 "2023-09-23T15:01:28Z")

</div>

Which Arduino board are you using and why are you using the Eepromex library ?

You cannot erase an EEPROM. Each cell will always have a value. You can, of course set each of the cells to a value that will indicate to you that the EEPROM has been intialised

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 3:11pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/4 "2023-09-23T15:11:49Z")

</div>

In my sketch not used eeprom liberary used eepromex liberary

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 3:19pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/5 "2023-09-23T15:19:00Z")

</div>

My board is arduino mega 2560  
And in my sketch  
Unfortunately, the sketch I have has already been used in this libraryI tried to replace the eeprom library, but the problem is somewhere in the command

> EEPROM.readFloat

And

> EEPROM.readByte

And

> EEPROM.writeByte

What is the alternative of these commands in the eeprom.h library?

I want to reset the eeprom memory to the initial value by pressing a key when turning on the Arduino board

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [September 23, 2023, 3:21pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/6 "2023-09-23T15:21:39Z")

</div>

From _EEPROMex.h_

```arduino
#ifndef EEPROMEX_h
#define EEPROMEX_h

#if ARDUINO >= 100
#include <Arduino.h> 
#else
#include <WProgram.h> 
#endif
#include <inttypes.h>
#include <avr/eeprom.h> // <---- here is included eeprom.h ;)

```

From [Arduino Reference](https://www.arduino.cc/reference/en/libraries/eepromex/)  
_Extension of the standard Arduino EEPROM library._

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 23, 2023, 3:25pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/7 "2023-09-23T15:25:51Z")

</div>

> [@hamedrepublic](#):
>
> What is the alternative of these commands in the eeprom library?

[https://docs.arduino.cc/learn/built-in-libraries/eeprom#get](https://docs.arduino.cc/learn/built-in-libraries/eeprom#get)

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 23, 2023, 3:26pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/8 "2023-09-23T15:26:46Z")

</div>

> [@UKHeliBob](#):
>
> You cannot erase an EEPROM

As I know that the meaning of earsing an EEPROM/Flash location is to put/store 1 (HIGH) into its all bit positions. In the Serial Programming Instruction Set of ATmega328P, there is an erase command which erases entire EEPROM/Flash memory in ONE GO. I understand that EEPROM.write() command first erases the target EEPROM location and then writes the new value.

 ![eraseEEpromFlash](https://europe1.discourse-cdn.com/arduino/original/4X/2/c/7/2c70ee8bb75f8f5aafd6468e5d9a3ba7b746d352.png)

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 3:30pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/9 "2023-09-23T15:30:05Z")

</div>

I read this tip, the problem is that my sketch uses the eepromex library

Now the problem is to replace the eeprom library with the eeprom.h library

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 23, 2023, 3:32pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/10 "2023-09-23T15:32:20Z")

</div>

Post your sketch.

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [September 23, 2023, 3:34pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/11 "2023-09-23T15:34:32Z")

</div>

The general procedure is just to write 0xFF to every location in the eeprom using a for loop.  
I'm not familiar with the EEPROMEX library, so not sure of the exact function call to do that.

The EEPROM library has been expanded since the EEPROMEX library was last updated, and will likely do everything itself. There are no special functions for each data type, the library recognizes the size of each data type (or structure) and automatically reads/write the appropriate number of bytes to eeprom (see the put() and get() functions).

---

<div class="post-metadata">

**Author:** ![JohnLincoln](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@JohnLincoln](https://forum.arduino.cc/u/JohnLincoln)\
**Post date:** [September 23, 2023, 3:45pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/12 "2023-09-23T15:45:28Z")

</div>

From the EEPROM library example "eeprom\_clear":

```arduino
 for (int i = 0 ; i < EEPROM.length() ; i++) {
    EEPROM.write(i, 0);
  }

```

As the EEPROMEx is an extension to the EEPROM library, then the above should still work.

EDIT, you can write 255 to each address instead of 0 - then the EEPROM becomes like one that has not been programmed.

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 4:11pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/14 "2023-09-23T16:11:47Z")

</div>

What is the difference between this

> EEPROM.readFloat

and

> EEPROM.readByte

this in eepromex liberary?  
What is the modified command for eeprom library؟

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 4:22pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/15 "2023-09-23T16:22:14Z")

</div>

Not working  
I have this error  
Class EEPROMClassEX.has no member named 'length'

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [September 23, 2023, 4:42pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/16 "2023-09-23T16:42:27Z")

</div>

> [@hamedrepublic](#):
>
> Class EEPROMClassEX.has no member named 'length'

Try using EEPROMSizeMega instead of EEPROM.length().

Also, it would be better to use update() instead of write(), that will only write the eeprom if the data differs from the current content of the eeprom, avoiding an unnecessary write cycle.

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [September 23, 2023, 5:02pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/17 "2023-09-23T17:02:33Z")

</div>

> [@hamedrepublic](#):
>
> have this error  
> Class EEPROMClassEX.has no member named 'length'

Why are you still trying to use EEPROMEX?

The library to use is EEPROM.h. Post a sketch and ask any questions if you are having issues using it.

[https://docs.arduino.cc/learn/built-in-libraries/eeprom](https://docs.arduino.cc/learn/built-in-libraries/eeprom)

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 23, 2023, 5:42pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/18 "2023-09-23T17:42:08Z")

</div>

> [@GolamMostafa](#):
>
> As I know that the meaning of earsing an EEPROM/Flash location is to put/store 1 (HIGH) into its all bit positions.

How is that erasing the EEPROM ? All that is doing is to put 0xFF in each cell of the EEPROM. If you read any cell after doing that how do you know whether the EEPROM has been "erased" or whether 0xFF happens to have been saved in that cell ?

The same goes for any value that you choose to fill the EEPROM with

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 5:44pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/19 "2023-09-23T17:44:32Z")

</div>

I am trying to replace the eeprom.h library, please help  
but the problem is somewhere in the command

> EEPROM.readFloat

And

> EEPROM.readByte

And

> EEPROM.writeByte

What is the alternative of these commands in the eeprom.h library?

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [September 23, 2023, 5:53pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/20 "2023-09-23T17:53:58Z")

</div>

[https://docs.arduino.cc/learn/built-in-libraries/eeprom](https://docs.arduino.cc/learn/built-in-libraries/eeprom)

EEPROM.read(address) Reads a byte from the EEPROM

EEPROM.write(address) Writes a byte to the EEPROM

EEPROM.get(address, data) Reads float data from the EEPROM

Please post the code you are trying to convert for more assistance.

---

<div class="post-metadata">

**Author:** ![hamedrepublic](https://avatars.discourse-cdn.com/v4/letter/h/22d042/32.png) [@hamedrepublic](https://forum.arduino.cc/u/hamedrepublic)\
**Post date:** [September 23, 2023, 6:31pm UTC](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451/21 "2023-09-23T18:31:07Z")

</div>

> #include "PinChangeInterrupt.h" // enables the interrupts at the other pin except the ones at the digital pins 2 and 3  
> #include \<avr/sleep.h\> // enables the sleep function  
> #include \<avr/power.h\> // power management  
> #include \<EEPROMex.h\> // enables some special functions for writing to and reading from EEPROM  
> #include \<EEPROMVar.h\> // enables some special functions for writing to and reading from EEPROM  
> #include \<SPI.h\>  
> #include \<Wire.h\> // IIC LIBRARY  
> #include \<math.h\> // enables complex math functions  
> #include \<Adafruit\_SSD1306.h\> // library for the OLED and graphics  
> #include \<Adafruit\_GFX.h\>

> traveled\_distance = EEPROM.readFloat(0);  
> traveled\_distance2 = EEPROM.readFloat (5);  
> used\_LPG = EEPROM.readFloat (10);  
> used\_LPG2 = EEPROM.readFloat(15);  
> LPG\_in\_tank = EEPROM.readFloat(20);  
> seconds\_passed = EEPROM.readFloat(25);  
> used\_Unleaded = EEPROM.readFloat(30);  
> traveled\_distance3 = EEPROM.readFloat (35);  
> used\_Unleaded2 = EEPROM.readFloat(45);  
> LPG1 = EEPROM.readByte (40);  
> LPG2 = EEPROM.readByte (41);  
> LPG3 = EEPROM.readByte (42);  
> LPG4 = EEPROM.readByte (43);

> ```
> EEPROM.writeByte(40, LPG1); //stores the new LPG coef.
> EEPROM.writeByte(41, LPG2);
> EEPROM.writeByte(42, LPG3);
> EEPROM.writeByte(43, LPG4);
> }
> 
> EEPROM.writeFloat (0, traveled_distance);
> EEPROM.writeFloat (5, traveled_distance2);
> EEPROM.writeFloat (10, used_LPG);
> EEPROM.writeFloat (15, used_LPG2);
> EEPROM.writeFloat (20, LPG_in_tank);
> EEPROM.writeFloat (25, seconds_passed);
> EEPROM.writeFloat (30, used_Unleaded);
> EEPROM.writeFloat (35, traveled_distance3);
> EEPROM.writeFloat (45, used_Unleaded2);
> 
> ```

[Next page](https://forum.arduino.cc/t/problem-using-the-eepromex-library/1171451.md?page=2)
