Problem Using the EEPROMEX library

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?

EEPROM Clear | Arduino

Regards

1 Like

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

In my sketch not used eeprom liberary used eepromex liberary

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

From EEPROMex.h

#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
Extension of the standard Arduino EEPROM library.

https://docs.arduino.cc/learn/built-in-libraries/eeprom#get

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.

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

Post your sketch.

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).

1 Like

From the EEPROM library example "eeprom_clear":

 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.

What is the difference between this

EEPROM.readFloat

and

EEPROM.readByte

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

Not working
I have this error
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.

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

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

1 Like

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?

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.

#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);