Hi,
For my ongoing clock project, I wanted to persistently store some data after turning off the Arduino. This should be easy since Arduino board has an on-board EEPROM. Unfortunately the Arduino standard EEPROM library only implements functionality for reading and writing a single bytes, which makes the EEPROM quite cumbersome to use.
This is why I wrote the EEPROMex library, an extension of the standard Arduino EEPROM library. It extends the functionality of the original Arduino EEPROM library with:
- Reading, writing to basic types like bytes, longs, ints, floats & doubles
- Reading, writing to single bits
- Reading, writing of any data format (for example structs)
- Reading, writing of arrays of any format
- Updating only changed bytes rather than rewriting all (thus reducing wear)
- (Very) basic memory management
- Debug functionality: limit number of writes. limit writing in memory range
You can download the library here:
http://thijs.elenbaas.net/downloads/?did=3 And find detailed explanation and samples of the functionality here
http://thijs.elenbaas.net/2012/07
/extended-eeprom-library-for-arduinoA simple example of reading and writing ints and floats:
#include <EEPROMex.h>
// Always get the EEPROM in the same order
// This will ensure that each variable gets
// the same adress after every restart
int addressInt = EEPROM.getAddress(sizeof(int));
int addressFloat = EEPROM.getAddress(sizeof(float));
double IntVarInput = 1234;
double IntVarOutput = 0;
double FloatVarInput = 101.101;
double FloatVarOutput = 0;
void setup()
{
Serial.begin(9600);
// Write an int to EEPROM, and then read it back
EEPROM.writeInt(addressInt, IntVarInput);
IntVarOutput = EEPROM.readInt(addressInt);
Serial.print(IntVarOutput);
Serial.println();
// Write a float to EEPROM, and then read it back
EEPROM.writeFloat(addressFloat, FloatVarInput);
FloatVarOutput = EEPROM.readDouble(addressFloat);
Serial.print(FloatVarOutput);
Serial.println();
}
void loop() {}
Let me know what you find!