Arduino Leonardo board can't upload anything

Hello everyone.

I'm using a Leonardo to build a makeshift game controller where I use the Keyboard.h library to simulate key presses when I press push buttons.

One thing led to another and while I was testing how the shift key works, I foolishly uploaded this sketch:

#include "Keyboard.h"

void setup() { Keyboard.begin(); }

void loop() {

    Keyboard.press(KEY_LEFT_SHIFT);

}

The problem is that I should have used some safety mechanism to stop the key press, so now I can't upload anything to the board. Yes, I have tried many renditions of using the reset button. If I hit upload, the "uploading..." portion appears for like 1/100 of a second. It's super short. There's no way I can press the reset button at just the right moment. I don't even think the reset button works in this case because the key press is interrupting it too quickly (or something like that lol)

I was looking into the "arduino as isp" example per this link: Installing an Arduino Bootloader - learn.sparkfun.com

But it seems like it wouldn't work with the Leonardo? I have an uno so I could upload the code, but I wouldn't be able to use the Leonardo as a target I don't think.

I'm kinda desperate to fix this asap because this is a class project and it would be a huge pain to trek out to microcenter to get another board :confused:

Burning the Caterina bootloader should work with Arduino as ISP but I've never tried it. Note that you need to use the 6 pin ICSP header on the Leonardo.

The below comment was wrong, see next post for possible solution.
What happens when you press the reset button? Do you have a slow glowing pin13 led? If so, that led should glow for approximately 8 seconds during which your current sketch is not running and you should be able to upload.

Tried to simulate it and I think the below will work

Disconnect Leonardo from PC.
2)
Reboot the PC; your PC currently sees the shift key being pressed, even if the Leonardo is disconnected. Rebooting will solve that.
2)
Wire the reset pin on the Leonardo to ground.
3)
Start the IDE
4)
Under file->preferences, enable verbose output during upload
5)
Connect the Leonardo; keep the reset pin wired to ground
6)
Start the upload ( of a safe sketch :wink: )

When the upload process starts, you will see the below

Sketch uses 5702 bytes (19%) of program storage space. Maximum is 28672 bytes.
Global variables use 224 bytes (8%) of dynamic memory, leaving 2336 bytes for local variables. Maximum is 2560 bytes.
PORTS {COM26, COM27, } / {COM26, COM27, } => {}
PORTS {COM26, COM27, } / {COM26, COM27, } => {}
...
...

The first two lines come from the compiler, the PORTS ... lines from the IDE trying to find a boot loader port and are repeated a number of times.
When you see the PORTS ... lines, disconnect the reset from ground.

After that, the last PORT ... line will show

PORTS {COM26, COM27, } / {COM11, COM26, COM27, } => {COM11, }
Found upload port: COM11

And the actual upload will start.

I tested this with a fail-safe version of your sketch and it worked.

Notes:
1)
The port numbers will (more than likely) be different for your system.
2)
If you don't get PORT ... lines, see if it helps if you hook up your Uno as well (just connect it, nothing else).

Thanks for the reply!

I try this when I'm in class next :slight_smile:

sterretje:
Tried to simulate it and I think the below will work

[....]

I just tried this and it works! Thanks so much, you're a lifesaver!