2

I am using an Arduino Mega 2560 board. I have tried connecting a 115 Ω resistor from 5V to Reset, and 10 µf capacitor form reset to GND (to disable autoreset), and the variables still seem to reset themselves when I unplug and replug-in the Arduino. Any way to stop this from happening?

Basically I am making a device that is sensitive to time, and must run for about 2 months, but if it is unplugged, it can't lose its place in time and reset the whole program.

I think one alternative would be for me to have it actually write how long it has been running into a .txt file on the microSD card and then verify that in the start-up...

Any ideas?

Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Aug 25, 2016 at 16:35
1
  • You have a power supply other than the USB connection, right? Commented Aug 25, 2016 at 19:04

4 Answers 4

5

Save the variables you need to EEPROM.

answered Aug 25, 2016 at 17:55
1

Arduino Mega board has RESET-EN "jumper". If you cut the trace, it won't reset MCU by DTR from USB-to-Serial chip. If you have to upload new sketch, you'll have to short it by piece of metal.

There is also possibility to use .noinit section for storing variables, so if you don't loose power, it won't get overwritten by automatic init. However, bootloader could be messing with that memory too. So it might not help without erasing this bootloader and using ISP(SPI) interface to program it.

Or you can use for example RTC (if you already have one) and it's battery backed RAM.

answered Aug 25, 2016 at 17:24
1

If you can't give the MCU enough warning of a power-down to save its critical variables, you'll have to keep it alive with batteries, sleeping if necessary, until the power comes back.

Tying Reset high won't help. The chip resets at power-up - that's built in. In fact, a power-up reset and a grounded-Reset-pin reset behave a bit differently - see the datasheet. Even if it didn't reset on power-up, the RAM needs power to maintain its contents, so it loses them when it drops.

answered Aug 25, 2016 at 19:14
0

Take power from UPS (uninterruptable power supply).

answered Aug 25, 2016 at 19:29
3
  • 1
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Aug 28, 2016 at 9:33
  • 1
    Not all questions have direct answer. Variables are stored in volatile memory that doesn't work without power and upon power reset variables are reset. There is no way to stop it from happening due to Arduino (and most other uC) design restrictions. But workaround solutions are possible, as almost always ;-) SD card, duplicate power supply, UPS, car accumulator of big capacity, Ethernet shield are just several examples. Commented Aug 28, 2016 at 18:46
  • 1
    The question is not on how to prevent power shortage but on restoring state after power shortage, hence I don't consider this answer relevant to the question. Also I guess the OP knows about UPS and did not need anyone to mention it. Commented Aug 28, 2016 at 18:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.