EEPROM forgetting data?

Hello,
I'm using an Uno R3 in my project. I'm trying to set a pH value, and calibrate a pH probe and store those values in EEPROM so the program can retain them in the event of a power off.
The pH value that's being set is a float type (with only the first decimal place really being important. )
the calibration values are calculated and stored as int.
I'm using EEPROM.put() and EEPROM.get() to read and write.

Upon the initial EEPROM.get(), there was gibberish, which I expected on the first go. I did an EEPROM.put() with my value and unplugged. Upon powering back up, the proper value was still there, as hoped.
However, I had it unplugged over the weekend and upon powering back up there was gibberish again. I started over, resaved (EEPROM.put() ), and it worked as intended over a few on/off cycles. But after several more cycles of on/off, it randomly popped up with gibberish again.

Does anyone know if this is normal? Maybe I can't mix and match data types (float in spot 0; ints in spots 1,2,3)? Should the float be an unsigned long (although the example: https://www.arduino.cc/en/Reference/EEPROMPut is using a float)?

Would a SD card be more reliable? It would just be major overkill for storing one float and three ints.

Please post the code.
There are a limited number of writes, 100K I think. Some code burns right through those.

Each eeprom storage address can only hold one byte.

Storing a float will take up 4 eeprom address locations ("spots"). A 16bit int will use two spots.

If a float is written to address 0 with eeprom.put(), your next storage address will need to be 4. If a 2byte int goes there, then the next int will need to be stored at address 6.

The eeprom library manages the breaking of values into bytes and storing them sequentially. It does not control the starting address to not overwrite existing data.

1 Like

not sure if that fixes the supposed forgetful EEPROM quite yet, but you fixed an issue I attributed to the sensor hardware. Apparently I was overwriting some of the bits from the float data. So thanks for that!

Still waiting for the code...

1 Like

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.