Arduino Leonardo - errors uploading programs after bad upload

Hello,

I've been having problems trying to upload code to my new Arduino Leonardo (appears to be genuine). I went to upload the code and forgot to change the "board" from UNO to Leonardo. Now, whenever I try to upload code I get a bunch of weird errors, which changes depending how I use the reset button as I start the upload.
[EDIT] Running an Acer Aspire 15 2016 laptop with Linux Mint 19.3

When I upload code without pressing the reset button:

avrdude: error: programmer did not respond to command: set addr

Sketch uses 3516 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 159 bytes (6%) of dynamic memory, leaving 2401 bytes for local variables. Maximum is 2560 bytes.


avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: verification error, first mismatch at byte 0x0000
         0x0d != 0x0c
avrdude: verification error; content mismatch
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader
avrdude: error: programmer did not respond to command: exit bootloader

When I press the reset button before uploading:

Sketch uses 3516 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 159 bytes (6%) of dynamic memory, leaving 2401 bytes for local variables. Maximum is 2560 bytes.
avrdude: ser_open(): can't open device "/dev/ttyACM0": Device or resource busy
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

When I press the "upload" button and then the reset button:

Sketch uses 3516 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 159 bytes (6%) of dynamic memory, leaving 2401 bytes for local variables. Maximum is 2560 bytes.


avrdude: Expected signature for ATmega32U4 is 1E 95 87
         Double check chip, or use -F to override this check.
Wrong microcontroller found.  Did you select the right board from the Tools > Board menu?

What can I do to try and fix this? I have additional arduino UNOs in case I have to burn a bootloader, but i can't find any tutorials addressing a UNO>>>Leonardo setup that explain the exact wire configuration.

Thanks in advance to anyone who can help!

I not sure if I can really help. The first error block indicates that you still have selected the Uno (or at least the IDE thinks so).

What happens when you disconnect the board; does the IDE still show /dev/ttyACM0 as the port? If so, it's not the Leonardo.

I suggest that you enable verbose output during upload in the IDE under file -> preferences and disable verbose output during compilation. After the compile, you should see something similar to below; there will be more info, I just found this one here on the forum during a quick search (I know what to search for so no attack on you).

Sketch uses 4128 bytes (14%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port COM26
PORTS {COM3, COM4, COM26, } / {COM3, COM4, COM26, } => {}
PORTS {COM3, COM4, COM26, } / {COM3, COM4, COM26, } => {}
...
...
PORTS {COM3, COM4, COM26, } / {COM3, COM4, } => {}
...
...
PORTS {COM3, COM4, } / {COM3, COM4, COM26, } => {COM26, }
Found upload port: COM26

Pressing reset while uploading might (not sure) corrupt the functionality of the bootloader. You can press and release the reset just after the memory usage is reported by the IDE.

For burning the bootloader, use the schematic of the Uno and a multimeter to determine which pins on the 6 pin header (furthest away from the USB port) have which function on the Uno; the pinout on the Leonardo's 6 pin header will be the same as the one of the header.

Right now the board isn't detected at all - this is the current verbose output:

Sketch uses 3462 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

I probably will try reburning the bootloader, but I haven't been able to find a tutorial or example that makes sense; you're saying that its the same as with the UNO>>>UNO setup but with the ICSP pins arranged differently? If possible, can you provide a schematic? I've bootloaded an UNO before but not a Leonardo.

What if you plug in the Leo., select the Board as Leo. and then (with a sketch in the IDE (Blink)), try to Verify it?
After that succeeds/fails, unplug, reconnect and try an Upload?

I've been able to verify several sketches fine before, such as a two-line serial.print code, the classic blink code, and even a blank sketch. That doesn't help though. as I still get the "couldn't find an Arduino on that port" error.

cpusley2018:
I went to upload the code and forgot to change the "board" from UNO to Leonardo.

There is a way you can "brick" your Leonardo by doing this in a specific way:
Tools > Board > Arduino Uno (or any other AVR board that doesn't use the ATmega32U4)
Sketch > Upload
While the compilation process is running, but before the upload process starts: Tools > Board > Arduino Leonardo ("Oops, I have the wrong board selected, better fix that")

The native USB boards like the Leonardo have some USB code that is added to your sketch which produces the USB CDC serial port. This code is not needed on the Uno because the Uno has a separate chip that provides the USB to serial interface. So what happens is that if you start the upload with Arduino Uno selected, the sketch is compiled without the USB code. Since the upload system is different for the Leonardo than the Uno, normally the upload would just fail and no harm would be done. However, if you switch boards after the compilation starts, but before the upload starts, then the Leonardo's upload system is used, but with the compiled binary for the Uno. So the upload finishes, and your Leonardo is "bricked" because it doesn't have a serial port any more.

Fortunately, the fix is easy, you just need to manually reset the Leonardo when the upload starts.

You need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button.

Do this:

Sketch > Upload

Watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

press and release the reset button.

After that, the sketch should upload successfully and you should be able to go back to uploading to your board as usual.


cpusley2018:
I probably will try reburning the bootloader, but I haven't been able to find a tutorial or example that makes sense; you're saying that its the same as with the UNO>>>UNO setup but with the ICSP pins arranged differently? If possible, can you provide a schematic? I've bootloaded an UNO before but not a Leonardo.

It shouldn't be necessary to do this if you follow my instructions above, but it's a good thing to know. The process of burning the bootloader on the Leonardo is the same, but the wiring you may find for burning bootloader on the Uno may not work for the Leonardo. On the Uno, the SPI pins are broken out to pins 11, 12, 13 as well as the 2x3 ICSP header. On the Leonardo, they are only broken out to the ICSP header. So if you find a wiring diagram of bootloading the Uno that shows the connections to the ICSP header, the same wiring will work for your Leonardo. But if you find a wiring diagram for burning the bootloader on the Uno that uses pins 11, 12, 13 on the target board, that wiring will only work for the Uno. This is important information in general for knowing which pins are SPI on the Leonardo. You can find more information on the "Connections" table of the SPI library's reference page:

pert:
There is a way you can "brick" your Leonardo by doing this in a specific way:
Tools > Board > Arduino Uno (or any other AVR board that doesn't use the ATmega32U4)
Sketch > Upload
While the compilation process is running, but before the upload process starts: Tools > Board > Arduino Leonardo ("Oops, I have the wrong board selected, better fix that")

The native USB boards like the Leonardo have some USB code that is added to your sketch which produces the USB CDC serial port. This code is not needed on the Uno because the Uno has a separate chip that provides the USB to serial interface. So what happens is that if you start the upload with Arduino Uno selected, the sketch is compiled without the USB code. Since the upload system is different for the Leonardo than the Uno, normally the upload would just fail and no harm would be done. However, if you switch boards after the compilation starts, but before the upload starts, then the Leonardo's upload system is used, but with the compiled binary for the Uno. So the upload finishes, and your Leonardo is "bricked" because it doesn't have a serial port any more.

Fortunately, the fix is easy, you just need to manually reset the Leonardo when the upload starts.

You need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button.

Do this:

Sketch > Upload

Watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.



press and release the reset button.

After that, the sketch should upload successfully and you should be able to go back to uploading to your board as usual.



---


It shouldn't be necessary to do this if you follow my instructions above, but it's a good thing to know. The process of burning the bootloader on the Leonardo is the same, but the wiring you may find for burning bootloader on the Uno may not work for the Leonardo. On the Uno, the SPI pins are broken out to pins 11, 12, 13 as well as the 2x3 ICSP header. On the Leonardo, they are only broken out to the ICSP header. So if you find a wiring diagram of bootloading the Uno that shows the connections to the ICSP header, the same wiring will work for your Leonardo. But if you find a wiring diagram for burning the bootloader on the Uno that uses pins 11, 12, 13 on the target board, that wiring will only work for the Uno. This is important information in general for knowing which pins are SPI on the Leonardo. You can find more information on the "Connections" table of the SPI library's reference page:
https://www.arduino.cc/en/Reference/SPI

I tried this and it didn't work.
I just successfully bootloaded the Leonardo, and it now registers with the IDE. For some reason though, it still has this error when I upload a code:

Arduino: 1.8.12 (Linux), Board: "Arduino Leonardo"

Sketch uses 3956 bytes (13%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, } / {} => {}
PORTS {} / {} => {}
PORTS {} / {/dev/ttyACM0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0
/app/Arduino/hardware/tools/avr/bin/avrdude -C/app/Arduino/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/arduino_build_240567/Blink.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/app/Arduino/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/colson/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: devcode selected: 0x44
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.15s

avrdude: Device signature = 0x0d3f0d
avrdude: Expected signature for ATmega32U4 is 1E 95 87
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

Wrong microcontroller found.  Did you select the right board from the Tools > Board menu?

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.