4

Note: This is a reference question (but feel free to write answers of your own!)


I uploaded code that contains a bug that causes my Arduino to immediately reset itself when starting using this code from the AVR libc FAQ. The built-in LED keeps flashing. Because it's in this state of constantly resetting, I'm unable to upload my sketch to it.

I tried holding the reset button while uploading and burning a new bootloader, but neither of those worked.

How do I get my Arduino out of this boot loop so I can upload sketches again?

glibg10b
  • 197
  • 5
  • If you are planning to answer your own questions, which is a great idea, it helps to note that it is a "reference question". That is, you are posting to help other people, not necessarily to canvas for answers. I did this a few times before people pulled me up on it. :) – Nick Gammon Jul 04 '22 at 10:11
  • Thanks for contributing these questions + answers to the community. – Nick Gammon Jul 04 '22 at 10:12
  • Thanks for the tip @Nick, I added a note to all of my questions :) – glibg10b Jul 04 '22 at 12:54

1 Answers1

4
  1. Start holding the reset button. This is to prevent the Arduino from entering the boot loop.
  2. Unplug the Arduino and plug it back in.
  3. Open a new sketch. Remove all of the code and replace it with int main(){}. This is to create a small program that will upload quickly.
  4. Start uploading the sketch. Avrdude will attempt to upload the sketch ten times -- each time it tries, the RX LED on the Arduino will flash briefly.
  5. Notice how often the LED flashes (0.2 Hz for me). Right before it flashes again, release the reset button. There's a small window of oppurtunity for avrdude to upload the sketch before the arduino starts up. If the TX and RX LEDs flash, success!
glibg10b
  • 197
  • 5
  • 1
    Since you have not specified which Arduino you have, answered your own question in quite short time, and commonly a sketch has no `main()`, this looks fishy. – the busybee Jun 30 '22 at 06:01
  • "answered your own question in quite short time" StackExchange [encourages this](https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/). This is not a Q&A site, it's a resource – glibg10b Jun 30 '22 at 07:54
  • "you have not specified which Arduino you have" This is not relevant – glibg10b Jun 30 '22 at 07:55
  • "commonly a sketch has no main()" All sketches have a [`main()`](https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/main.cpp), you just can't see it. This `main()` can be overridden, which is what happens in my answer – glibg10b Jun 30 '22 at 07:58
  • "this looks fishy" What fishy agenda could I possibly have? My answer hurts nobody, but it can help some people. I don't gain any rep from it (thanks to you, I just lost some) -- I posted it solely to help others with the same problem – glibg10b Jun 30 '22 at 07:59
  • 1
    decent answer to a poorly written question... – dandavis Jul 01 '22 at 19:50
  • 1
    I just gave you some rep. Don't worry too much about rep. If you post good questions and answers you will soon have so much rep you won't know what to do with it. ;) – Nick Gammon Jul 04 '22 at 10:14