How to erase a sketch on a Leonardo

Hi,
I'm new to the forum and not sure if this is the right place to ask this question - sorry if it's not.
I have uploaded the following sketch to a LeoStick(Leonardo):

#include "Keyboard.h"
#include "Mouse.h"
void setup() {
Keyboard.begin();
Mouse.begin()

}
}
void loop() {
Keyboard.write('H');
Keyboard.write('E');
Keyboard.write('L');
Keyboard.write('L');
Keyboard.write('O');
Keyboard.write('!');
}

Unfortunately the sketch now takes control of my computer and I can't upload a new sketch as I can't control the keyboard or mouse while the Leostick is plugged in.

When I use the Arduino Create (web editor), with the Leostick plugged it, the compile/upload button (the one that looks like an arrow) is unable to be pressed as it is 'greyed out'.

In effect the sketch above locks me out of the control of my computer.

Is there a way to erase a sketch from a Leonardo/Leostick without needing to have it plugged in?

Thanks in advance

  • Press the reset button on the Leostick twice quickly. You should now see the LED pulsing to indicate it's in bootloader mode and it should not be emulating keystrokes.
  • From the port menu, select the port of the Leostick. While in bootloader mode, the port of the Leostick may be different than the one while the sketch is running so don't assume you already have the correct port selected.
  • Do an upload.

Thanks pert for the reply I was very excited when you replied and after 2 and a half hours of doing other stuff i get back the computer and upload Blink! (To my LeoStick!) Thank you so very much!

You're very welcome. I'm glad to hear it's working now. Enjoy!
Per

In future projects, implement a means to stop the hid output.

Something like

if (digitalRead(somePin) == LOW)
{
  do keyboard/mouse stuff here
}

If you want to upload or edit your code, simply make the pin high and hid output will stop

sterretje:
In future projects, implement a means to stop the hid output.

Something like

if (digitalRead(somePin) == LOW)

{
 do keyboard/mouse stuff here
}



If you want to upload or edit your code, simply make the pin high and hid output will stop

If you set the pinMode() to INPUT_PULLUP then you would jumper the pin the Ground to get your code to run and remove the jumper to stop it.

Thanks for all the replies. Its so nice know that I can ask Questions and get some help.
Thanks again for all your help.

:slight_smile: