0

When starting the serial monitor in IDE I want to save important data to EEPROM before the Arduino Uno restarts. I do not have physical access to the Arduino so a "press button" solution does not work here.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Apr 22, 2017 at 15:19

2 Answers 2

3

You can't. There is no way of detecting if the serial monitor is open or not.

However, you can disable the automatic reset and provide some functionality in your code for saving data to EEPROM when prompted through a command entered on the serial monitor (if you now need to even save the data).

answered Apr 22, 2017 at 15:29
1
  • you did it again. That is a very cool trick. Thank you for teaching me that one. I don't understand how the 120 Ohm value was figured out, but this is something I will put in my mental toolbox for sure. Kudos. Upvote. Commented Apr 23, 2017 at 1:25
0

What you really want to do is to store the data before the computer shuts down.

Here is what I did. I am running a Mega in a car and using it for a lot of things. The Mega receives its power from the ignition switch. When the ignition switch it turned on, the Mega boots up. In the "setup" section of the program, I set a digital output HIGH. The digital output is tied to the coil of a relay. One side of the relay is tied directly to the battery. Once the relay is energized, the relay supplies power to the Mega. I have a digital input tied to the power coming from the ignition switch through a resistor and a zener diode to clamp the voltage at 5 volts. In the main program I monitor the input power digital input. When I see the power go down,(ignition switch is turned off), I run a Shutdown program that stores all of the data I need stored to the EEProm. Once that is done, I set the digital output LOW. This de-energizes the relay and removes the power from the Mega. If you push the reset button, that is a hardware reset and you lose your data. If I want to reset the computer, I simply run the "Shutdown" routine. I can do that using a remote switch that drives a digital input.

answered Apr 25, 2017 at 2:17

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.