The usual reason is a bug in your sketch that overwrites variables used by the CDC stack that is part of the uploaded code. Does this also happen when you upload an innocent sketch like blink?
If your question is how to upload again, tap the reset button (you might need a double tap) just before the IDE reports the memory usage.
This normal behaviour with the Leonardo. The Leonardo has a native USB Interface. and it connects to the computer as two different devices: one for bootloading, and one for normal operation. So you see a different device while uploading code as when your sketch is running. The bootloader device disappears when your sketch starts. It then reconnects as normal 'Leonardo'.
I used the BLINK and it worked - trying my program - it did not worked - until I figured out
to wait for SERIAL.
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
I don't know why I forgot this in this program. Normally it's always in
I know to push the reset at LEONARDO for programming.
But that's not an option, because my raspberry should be a gateway for programming.
Laptop -> SSH raspberry -> USB Adrduino
The Arduino is on the roof and it's not easy to get there. So in the development and test phase, I use the raspberry as gateway.
I read about bringing the LEONARDO in programing mode by open the serial with 1200 boud and closing. I didn't work. So I read about not only open,but setting (or desetting) DTR. So I used a phyton script before and it worked.
Rather than requiring pressing the reset button before an upload, the Leonardo ETH is designed in a way that allows it to be reset by software running on a connected computer. The reset is triggered when the Leonardo's virtual (CDC) serial / COM port is opened at 1200 baud and then closed.
So no DTR thing needed.
The trick is to wait at least 1sec after closing the serial with 1200 boud.
And I found some snipplets to open/close the serial with 1200 and waiting 1sec and then doing the programming.
the programmer setting for AVRDUDE was wrong
it must be -c avr109 and the board must be -p m32u4
And I never used the RESET pin when connecting a W5500 module. But with LEONARDO I have to !!!
Otherwise it initialize the W5500 module (yellow led goes on), some data comes or is going out (green led) then the W5500 looses connection (yellow led off). After some seconds the game starts over again.
So you see it was a curvy way to get the goal. Changing this - changing that.....
Boards with native USB don't use DTR for reset; DTR only applies to boards that have a dedicated TTL-to-USB converter.
Software reset (1200 baud) only applies to boards with native USB. It will not work however if your board is not recognised while running your sketch; I'm surprised that you managed to get that working if your board is not recognised by the OS.
Software reset takes some time (your 1 second). You have approximately 8 seconds (Leonardo) after issueing the reset to start the upload; that's the time that the bootloader stays active after the reset.
You don't need while (!Serial). If you don't want to miss the first messages that you print, it is needed; if you don't care about that, don't worry about it.