Go Down

Topic: Using EEPROM.get  (Read 96 times) previous topic - next topic

Dencsa

Jul 14, 2018, 01:02 pm Last Edit: Jul 14, 2018, 03:16 pm by Dencsa
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 :D


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

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

sterretje

Code: [Select]
...
...
  //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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Koepel

#2
Jul 14, 2018, 02:03 pm Last Edit: Jul 14, 2018, 02:04 pm by Koepel
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.

Dencsa

Thank you very much guys :)

Go Up