I am setting up some hardware that is designed to never turn off. But as we know sometimes you loose power or a circuit breaker trips etc. I have set up a capacitor bank to allow sufficient time to write to EEPROM before Arduino looses all power, therefore i am only writing to EEPROM when power loss is detected, which reduces significantly the amount of writes to the Arduino. However i have learned that i can only send 8 bit numbers to EEPROM and millis is much larger. Therfore my Question:
Can you use EEPROM to save millis() and then upload millis back on to continue timer at exactly the point it left off?
You can store a 64 bit number in eeprom by storing 8 bits at a time, using a total of 8 memory address. then when the number is used, 8 reads, and put the number back together.
Space is an issue and so are my inputs and outputs, trying to save on room. Though i believe i can do some math and instead of just saving milli's I just save the time elapsed and include that in the calculation of my timer so it will automatically adjust.
If you want to keep track of how long the device has been active you can implement a software timer. Keeping track of milliseconds for life time monitoring is probably not necessary. Counting full seconds should be good enough.
Thanks i think this will help as i will be storing more than 8 bits, but in essence it seems unreasonable to read all of millis, so i'll settle with just reading the time difference and storing that.
Can you show your sketch ? and tell how you want to continue ?
When the Arduino starts, all the libraries are initialized and the hardware is initialized.
Suppose your sketch does something at certain times of the day (open the curtains, turn on lights, and so on) then the TimeLib + TimeAlarms library can be used with a RTC and in setup() you need a lot of code to check everything and take action if needed.
@Klaus_K, I did that in a project and it seems to work. After a few years I found that it did not work so I don't know how many seconds the device was on.