Go Down

Topic: Writing to/reading from the EEPROM only once or an alternate way (Read 112 times) previous topic - next topic

Yami89

Hi, I'm working on a project which turns on a fan(connected to a relay) when a certain threshold in temperature is reached. I have included a piece of code where the user can set the threshold value for. But it has to be done only once or twice.

I know the value has to be stored in the EEPROM since I need the value to hold when the power to the arduino is gone and comes back. Now my question is there way to write to the EEPROM once and not have to read from it all the time when the power is interrupted, or better yet do it without having to write to the EEPROM.


Lucario448

Now my question is there way to write to the EEPROM once and not have to read from it all the time when the power is interrupted, or better yet do it without having to write to the EEPROM.
Impossible.
You have to write to the EEPROM if you need persistent data (but what you can do, is to avoid an attempt of overwritting the same existing value); if something changes, you'll have to save those changes by writing to the EEPROM once again. THERE'S NO ESCAPE ON THAT!.
However, if you insist in writing only once ever (which kinda beats up the purpose of the EEPROM), then you'll have to write the corresponding "flag" (aka boolean value) as well.

Same for the retrieval (reading), don't expect that the Arduino will "magically" recover those values after a power cycle, not without calling the respective procedure (which is reading from the EEPROM, at least once in the setup()).


To understand why all this, then look for the definition of the terms "volatile memory" and "non-volatile memory"

Yami89

Thanks very much for the help. Isn't there any way to change the value of a global variable within the code and make it "permanent" hehehehe. As I feel that writing the values into the EEPROM is quite a lot to do for a very simple task that I have to achieve.

sterretje

What is the problem with reading the eeprom back once in setup?
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.

Lucario448

As I feel that writing the values into the EEPROM is quite a lot to do for a very simple task that I have to achieve.
Well, it's time-consuming (in the milliseconds range) and decreases it's endurance; so you're mostly right. What is not "a lot", is the effort to use the EEPROM in code.

First of all, why you're concerned about it? Have to write data too often or too quickly?

Go Up