Overview

EEPROMStore is an Arduino library to look after saving and loading data from the EEPROM. Data in the EEPROM is not lost when the device loses power, or is reset, so it is a good place for storing program configuration. A check sum is stored with your data so the library can detect an EEPROM that hasn’t been initialized, or may contain invalid data. The EEPROMStore is part of the MegunoLink Arduino library.

The EEPROMStore works with data that lives in a structure. A structure is one kind of complex type. But it isn’t very complicated; a complex type is just a collection of simple types. And a simple type is something like an int, or long, or a byte. The structure groups them together so we can refer to them as a single thing.

Here’s a simple structure that has two members: temperature and humidity set points:

A struct is used for the EEPROMStore to make it easy to load and save a group of values all together.

A structure used with the EEPROMStore must also define a reset method. The reset method is called by the library whenever it detects invalid data. Typically this occurs the first time your sketch is run…because you haven’t saved any data at that point. The Reset method gets called to initialize all the variables in the structure.

So, to store a humidity and temperature set-point for a green house controller, we might declare a structure like this:

Storing the configuration in the data structure is then simply:

Configuration values are accessed through the Data property. Previously stored values are loaded automatically when the device is reset. Call the Save method to update the EEPROM when values are changed.

EEPROMStore Reference

The EEPROMStore is a template that takes a single argument: the name of the structure type to store. You’ll also need to include the library header file to use it:

The last saved value will be loaded automatically when your sketch starts. If there is no previously saved value (because this is the first time the sketch has been run) the default value is set using the Reset() function.

Data Property

The EEPROMStore variable has a Data property. With the type of the structure you’re storing. You could print the current values using something like this:

And set a new value like this:

Changing the value in the Data member doesn’t change the value stored in the EEPROM. You need to call the Save method.

Saving

To save the current value of data to the eeprom, call the Save method.

Loading

To overwrite the current value of the data with the value last saved in the EEPROM, call the Load method:

Reset

To replace the current value of the data with the default value, call the Reset method:

This doesn’t update the value in the EEPROM however. Call the Save method to do that.

Start typing and press Enter to search