Using EEPROM.get

Hi, I am a beginner programmer and I have some problems with my eeprom.get. It’s just not working properly and I tried many ways to resolve it but I still can’t. I would be very thankful if someone could help me with this :smiley:



//eeprom slider1
double slider1 = virtuino.vMemoryRead(21);
EEPROM.put(0, slider1);

//eeprom slider2
double slider2 = virtuino.vMemoryRead(22);
EEPROM.put(1, slider2);

...
...
  //eeprom slider1
  double slider1 = virtuino.vMemoryRead(21);
  EEPROM.put(0, slider1);

  //eeprom slider2
  double slider2 = virtuino.vMemoryRead(22);
  EEPROM.put(1, slider2);
...
...

Doubles take 4 bytes. So your store 4 bytes (slider1) at address 0 and next next 4 bytes (slider2) at address 1; as a result, you overwrite 3 bytes of the first 4 bytes. This applies to all your put statements.

The documentation should explain it better. https://www.arduino.cc/en/Reference/EEPROMGet.

The first parameter is the address in bytes of the EEPROM. Location 0 is the first byte of the EEPROM. Location 1 is the second byte of the EEPROM.

The second parameter can be anything with any size. For example 'uint_8' for a single byte, or 'float' for 4 bytes. You have to keep track of the number of written bytes yourself ! When writing a two-byte integer to location 0, the next data can be written at location 2.

Do you use an Arduino board with a AVR microcontroller ? Those have only 4 byte 'float', not a 8 byte 'double'.

I suggest to change all the 'double' to 'float' and write in the header how the EEPROM data is organized, with the exact EEPROM addresses.

When posting this, sterretje already explained it. O, well, I'm going to post this anyway. P.S.: A 'double' is 8 bytes with SAMD processors, but SAMD processors don't have EEPROM.

Thank you very much guys :)