eeprom and structure and adressing

Hi
anyone having an example how to use , store, a structure in eeprom?

Thanks T

Take a look at the put method of the EEPROM class. It can write any object or structure to the specified address.

Example

#include <EEPROM.h>

struct myObject //structure tag myObjcet contains 3 members
{
  float field1;
  byte field2;
  char name[10];
};

myObject customVar = //members initialization
{
  3.14f,
  65,
  "Working!"
};

myObject customVar1;  //variable to receive values after reading
void setup()
{
  Serial.begin(9600);
  EEPROM.put(0x0234, customVar); //all 3 members of structure are stored into EEPROM starting at location 0x0234
  EEPROM.get(0x0234, customVar1); //read after write verification
  Serial.println(customVar1.name[0]);  //shows W
  Serial.println(customVar1.field1, 2); //shows 3.14
}

void loop()
{

}

Memory Map (after the structure is stored into EEPROM)
dsz.png

dsz.png

very nice,
thanks a lot
:slight_smile:

Hi
running this on an ESP I have an error after the EEPROM.put

does this need to be adjusted for ESP?

Thanks

Does your ESP have an EEPROM?