1

I would like to program the arduino such that if I reset it by disconnecting and then reconnecting the usb.. A particular led glows BUT If I press the manual reset button on my nano... I want a different led to glow. How can I achieve this. I have 2 leds and my nano... Along with the laptop and any other necessary components.

asked Feb 6, 2017 at 17:22

1 Answer 1

2

The MCUSR register (page 79 of the datasheet) tells you what kind of reset happened most recently. As long as the USB interface chip on your nano isn't controlling the RESET pin without the port being opened (i.e., toggling it at power up regardless of the USB state) then you could query that register to see how it reset:

if (MCUSR & (1 << 0)) { // POR
 digitalWrite(4, HIGH);
} else if (MCUSR & (1 << 1)) { // External Reset
 digitalWrite(5, HIGH);
}

However, if the USB chip does toggle the RESET pin then there is no way you can distinguish between the two resets since they are bot the same "external" reset using the RESET pin.

answered Feb 6, 2017 at 18:18
2
  • 1
    Note that the information in MCUSR is lost on boards running optiboot, such as Uno. Luckily the standard bootloader on the Nano doesn't do this so it likely won't be an issue in this case but it's worth mentioning because it's common for people to burn the optiboot bootloader to Nanos as it's otherwise far superior to the stock one. Commented Feb 7, 2017 at 6:50
  • If the usb-to-serial is actually resetting the MCU right after power-up, you could try using the PORF bit in the MCUSR. When first power-on, this bit is set. If you clear this bit, and then press the reset button, this bit will still be 0 when the sketch start again. Commented Feb 7, 2017 at 10:15

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.