Hardware Reset

Question, is there a way to test if the Arduino had a Hardware reset via the reset button or from some unknown reason that caused it to reboot?

The reason I asked is, I would like for a ESC Calibration routine to run only on the initial power up and no other time in the event of a reset.

Yes. Search the datasheet for the MCUSR register.

The same code gets run when the Arduino resets, whether from power on, pressing the reset button, opening the serial port, or poor code causing a reset.

So, no, when the Arduino starts up, you can not tell why.

run only on the initial power up and no other time in the event of a reset

This begs the question, why does it have to be reset?


Rob

This begs the question, why does it have to be reset?

Well a reset (at least power-up or manual/auto reset) is required to activate the Arduino bootloader program. But if your point is that good program structure should not require a 'running reset', I agree.

I guess one exception would be if the watch dog timer was being utilized, but there is a way to determine in code if the watch dog timer did the biting.

Lefty

But if your point is that good program structure should not require a 'running reset', I agree.

Yes, that's what I was referring to.


Rob

Ok, perhaps the best way is to get it to save a value to EEPROM on startup after it has run the ESC calibration routine.

So the code would be:
Check for value in EEPROM
if value exists, ignore calibration code
else, run calibration code and write value to EEPROM

Then you could have a physical button to reset the value in EEPROM if you wanted to run the routine on next startup.

Mowcius

Ok, perhaps the best way is to get it to save a value to EEPROM on startup after it has run the ESC calibration routine.

So the code would be: Check for value in EEPROM if value exists, ignore calibration code else, run calibration code and write value to EEPROM

Then you could have a physical button to reset the value in EEPROM if you wanted to run the routine on next startup.

Mowcius

Good Point, thank you.