1

I just uploaded a sketch to my Arduino Leonardo, which presses a key on the keyboard. The code was unfortunately bugged and now as soon as the Arduino is powered on, the key is being pressed.

When I try to upload a new sketch that fixes the issue, I am unable to do so as the Arduino is executing the sketch, preventing the new sketch from being uploaded.

How can I prevent the Arduino from executing the sketch once powered on? Pressing the reset button or wiring it in does not work...

  • Welcome to Arduino Stack Exchange. Please take a moment to look at the tour at arduino.stackexchange.com/Tour to get the most out of this site. Meanwhile, we're going to need more info in order to help with this question. Start with posting the code. – SDsolar Jul 25 '17 at 3:22
  • I no longer have the code, it presses a key as soon as the code starts... I can't upload a new sketch because of the old code executing and pressing the key... – EoinAviation Jul 25 '17 at 3:25
  • 2
    Yeah, you said that already. Normally you have to press the reset button and hold it until just the right instant during upload. It usually takes several attempts to hit it just right. From now on, code a little delay in setup for projects like this to give yourself a chance. – Delta_G Jul 25 '17 at 3:37
  • Releasing the reset button at the right time as @Delta_G wrote should make it work. If you enable more output for the upload in the preferences, then you should release the reset button after the polling starts. If that fails, you could burn a new bootloader into the Leonardo to stop the current sketch, but then you need a programmer. – Jot Jul 25 '17 at 5:09
4

The Leonardo should wait a couple of seconds after resetting to see if a new sketch arrives.

  • Power off the board completely (remove the USB cable).

  • Hold down the Reset button, and keep it held down (or, run a jumper wire from the RESET pin to the GND pin). This stops the problem sketch from starting.

  • Still holding down Reset, reconnect the USB cable.

  • Start uploading a sketch that does not have this problem (eg. Blink) Once the IDE reports "Uploading" release the Reset button (or remove the jumper wire).

  • After 6 attempts, it finally worked. Thanks mate!! – EoinAviation Jul 25 '17 at 9:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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