EEPROM put and get methods
Posted: Fri Apr 10, 2015 12:55 pm
I haven't figured out how to contribute directly via github yet, but I modified the EEPROM code with some convenience methods to add get/put methods.
I tested it with all primitive data types and arrays, plus some typedef'd struct data, and it all worked fine.
Example code to store data:
And to retrieve data:
You pass the variable name where you want the data to end up into the function.
Both put and get will return the number of bytes stored/retrieved, so you can easily increment your address counter to store many variables.
I tested it with all primitive data types and arrays, plus some typedef'd struct data, and it all worked fine.
Example code to store data:
Code: Select all
EEPROM.begin(512);
int addr=0;
addr += EEPROM.put(addr, myFloat);
addr += EEPROM.put(addr, myInt);
EEPROM.end()
And to retrieve data:
Code: Select all
EEPROM.begin(512);
int addr=0;
addr += EEPROM.get(addr, myNewFloat);
addr += EEPROM.get(addr, myNewInt);
EEPROM.commit();
EEPROM.end()
You pass the variable name where you want the data to end up into the function.
Both put and get will return the number of bytes stored/retrieved, so you can easily increment your address counter to store many variables.