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.

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).

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.
    – SDsolar
    Apr 23 '17 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.