EEPROM ovf error when reading GPS data


I am trying to write GPS latitude and longitude data to EEPROM using the EEPROMex library (both latitude and longitude are being stored as floats). I can read successfully latitude from EEPROM immediately after writing it, but once I write longitude to a different address, for whatever reason when reading the latitude I get "ovf".

Here is a snippet of my code:

float Lat = GPS.latitude;
EEPROM.writeFloat(address, Lat);
float eLat = EEPROM.readFloat(address); // **** this works fine
Serial.print("Latitude: ");
Serial.println(Lat, 4);
Serial.print("EEPROM Lat: ");
Serial.println(eLat, 4);

float Lon = GPS.longitude;
EEPROM.writeFloat(address, Lon);
float eLon = EEPROM.readFloat(address); // **** reading longitude here works fine as well
Serial.print("Longitude: ");
Serial.println(Lon, 4);
Serial.print("EEPROM Lon: ");
Serial.println(eLon, 4);
// **** if I try to read latitude here (or in another program), I get the "ovf" error.

Not sure why I am getting this ovf error, especially when longitude is being written to a different address. I need to be able to recover both latitude and longitude coordinates in a different program, after the arduino is shut off. Any help would be greatly appreciated. Thank you!


The problem might be with address. If it is a straight char pointer, it might be incrementing by 1 byte instead of the desired 4 bytes.

I just initialized "address" as an int, starting at 0 and increments by 1 each time something is written to EEPROM. Is there another type I should use to increment?

Assuming that the address in the EEPROM is by byte, you need to add 4 to address each time. When you use real pointers, C and C++ automagically increments by the size of the object.

Personally, I would write only bytes and use a union to break the float apart, but that is just me.