Backup for last state of task on Arduino

Hello Every one

For present Time I am working on a normal MEGA board

Is it possible to keep the last function as it is there after getting turned of the device ?

Or say

after getting all the indicators display motors relay deactivated is it possible to store the last operation

Suppose i designed a counter and started counting and when it comes to 5 or 6 , suddenly power goes off and I want to see again the 5th or 6th count after the power is retrieved

Please help me in doing that !!!!!!

Thanks !!!!!!!!!!! :blush:

Use EEPROM. Just keep in mind, you can't write to it more than about 10,000 times.

Would you please elaborate ??
I don't have any idea

where to get this EEPROM or what number or further details ?

You can find all that in the Arduino documentation on this site. Look under "reference".

Actually, always look there first.

1 Like

I use FRAM and keep several copies so I can detect a bad write. FRAM operates at read/write speeds with trillions of R/W cycles. There is no delay while it is being written as there is in EEPROM.

EEPROM memory is persisted after the device powers off.

Example...

#include <EEPROM.h>

uint16_t counter = 0;

void setup()
{
  EEPROM.get(0, counter);   // Get the counter from the EEPROM.
  
  
  Serial.begin(115200);
  Serial.println("Starting");
}

void loop()
{
  Serial.println(counter++);

  EEPROM.put(0, counter);    // Update the counter in the EEPROM.

  delay(1000);
}

Output... after restarting 3 times.

14:13:17.905 -> Starting
14:13:17.955 -> 1
14:13:18.968 -> 2
14:13:19.964 -> 3
14:13:20.974 -> 4
14:13:21.978 -> 5
14:13:24.172 -> Starting
14:13:24.172 -> 6
14:13:25.184 -> 7
14:13:26.181 -> 8
14:13:28.716 -> Starting
14:13:28.716 -> 9
14:13:29.710 -> 10
14:13:30.713 -> 11
14:13:31.758 -> 12

1 Like

I see . . le me go thru that !!

Snippet of a google

It is unwise to rely on anything more than 100,000 write cycles

which means that @red_car's example would only be reliably reliable for 1.15 days.

So don't run that all day long…

Write way less often, or write only when you need to write changes or detect power failure and write in the list last gasps of your ability to do.

a7

O in that way . .

So we can use it while switching of power on daily basis too . . Right ??

I mean before winding up the whole day's task

Yeah, once a day for 274 years. By which time something else will no doubt have become a bigger problem. :expressionless:

a7

Ya life after 274 years . . .

So what about this FRAM ? what actually it is

@alto777 ison the right track.

There are several threads here that explain power failure / EEPROM save states.

I see . .

OK how to make this enable and disable as per use ??

simply this /* & */

or something else like a command from another push button thing ??

those are traditional C ‘block comments’

Ya True . .

What if we go for a small size external battery to keep the unit only OFF and cut all the earthing of rest of the devices ?

Well more like cut the power to the rest of the devices.

You may want to look into sleep modes that are available and techniques for getting the most out of them:

a7

You can use the EEPROM in the processor. THere is an example in the Arduino examples directory (didn't we have this discussion before :slight_smile: )

You would have to write to the EEPROM every time the state had changed so you risk "wearing out" the EEPROM. I suggest you get it going, saving your data at EEPROM address 0. Once it works you can look at ways to address EEPROM wear out.

Remember with all things Arduino ..... baby steps.

Ya we discussed . . but actually a bit different function I need to have here !!!

Its like I want to make the Arduino unit ON for 24x7 and want to switch OFF rest of the peripherals like LCD Display units Indicators relays motors blah blah things

This is just like the PC mother board 3V Cmos battery do for the setup boot options Clock Time Date etc etc etc etc !!

That's the main motive !

A primitive but functioning approach.

I'm trying to flesh out this idea but have nothing worth posting right now.