Help! Arduino Leonardo stuck in loop!

I was trying out the keyboard module, and I made it so it infinitely presses enter when you plug it in, so I can't move my mouse to upload a new sketch. Is there anyway to fix this? I tried holding down the button, but the port would not show up to upload the sketch. Thank you for any help.

Some are able to upload after releasing the reset button, but that does not always work for me. I had to burn the bootloader into a Leonardo board a number of times. Then you have your board back.

I use a USBASP with a 10-to-6-pin adapter, but others use a Arduino Uno.

Is there any other solution? I just got my arduino out of the box today, and I didn't want to mess anything up so early :frowning:

Double tap the reset button.

Fixed it! Double tapped the button right when it was plugged in, then pushed CTRL + U to upload the code.

  1. For a Leonardo,a double tap is not needed; the bootloader is activated (for about 8 seconds) when you press and release the reset.
  2. That will work with a small sketch; if it takes too long to compile (8 seconds), that trick does not 100% work.

The more reliable trick is to keep the Leonardo in reset while compiling; when the IDE reports the memory usage, release the reset button.

To prevent future problems where the Leonardo spams the PC, I suggest that you implement a safety mechanism as shown below

const byte safetyPin = A0;

void setup()
  pinMode(safetyPin, INPUT_PULLUP);

void loop()
  if (digitalRead(safetyPin) == LOW)
    // do HID stuff here

Pick any pin that you have available; only if the pin is shorted to ground, the Leonardo will perform HID functionality (you can reverse the logic if needed).

Last warning: the PC remembers key presses, if you forget to release a key after you pressed it, your PC might end up in a unusable state (e.g. <ctrl> pressed). The fix is to connect the Leonardo to the PC while the reset button is pressed and keep the reset button pressed till the IDE reports the memory usage and starts the upload.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.