ksor
August 21, 2021, 1:44pm
1
I have 3 bytes to store in the EEPROM and I could do it like
EEPROM.put(0, b1);
EEPROM.put(2, b2);
EEPROM.put(3, b3);
and then it will ONLY be RE-stored if it in fact DIFFERS from the value allready stored.
Is that the case too if the 3 bytes are wrapped into a struct and only - let's say - 1 of them has a new value - something like this:
struct myStruct {
b1;
b2;
b3;
}
EEPROM.put(0, myStruct);
AFAIK, the EEPROM library can store any data type, including a struct. The standard EEPROM library performs an update, not a blind write. It will only write information that has changed.
Although it's a good feature, you shouldn't write code that depends on it.
ksor
August 21, 2021, 2:18pm
3
Ha, ha, the examples show it CAN handle struct but my Q was about the members of the struct.
If ONE has a new value will ONLY this single ONE be RE-saved and the other members NOT - just to NOT eat up of the 100.000 times the EEPROM can be written to ?
Have you looked at the library source code? What about the reference page for put()?
"This function uses EEPROM.update () to perform the write, so does not rewrites the value if it didn't change."
It would not take much effort to write a small sketch to find out for yourself. Experimenting is allowed if not encouraged.
1 Like
ksor
August 21, 2021, 3:07pm
6
Yeah, that's why I asking - the STRUCT IS changed if just one of its members has changed - so the STRUCTURE will be RE-saved
OR is it the individual members that is evaluated for changes - that's my Q ?
ksor
August 21, 2021, 3:09pm
7
Yeah, that would only take 100.000 or more put's - no big deal at all ... or ... ?
The eeprom is written byte by byte and .update() is also on a byte basis. Each byte is evaluated for change from what is stored at the address and only written if different.
Koepel
August 21, 2021, 3:44pm
9
Source code of writing the struct byte by byte with a 'update' for each individual byte: https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/EEPROM/src/EEPROM.h#L140
ksor
August 21, 2021, 7:41pm
10
Not stuff for a novice like me
Have you verified what has been told in Post-8?
ksor
August 22, 2021, 5:27pm
13
The novice I am I can't manage the cpp code for the EEPROM.
It's working now with get and put a struct and 100.000 times is way enough in my life time.
@ GolamMostafa
How would you verify that an unchanged byte in a struct is indeed unwritten and not written again with the same value?
ksor
August 22, 2021, 6:38pm
15
Another posting shows the cpp-file for the EEPROM but it's out of my reach to really get something out of it ...
I will try to find if some means does exist.
It does exist. Just read the cell and compare with the value that you want to store; if it differs, write the new value, else do nothing.
That's the principle used in EEPROM.h (ArduinoCore-avr/EEPROM.h at master · arduino/ArduinoCore-avr · GitHub ) as far as this untrained C++ programmer can see.
system
Closed
December 22, 2021, 2:58am
18
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.