Cannot upload to Leonardo

I have tried nearly every troubleshooting method I can find and nothing seems to work.

I'm using a Longan CanBed V1.2e CANBED V1 - Longan Docs that uses Atmega32U4 chipset. With IDE 2.0.4.

For testing I'm just trying to upload the basic BLINK

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

I usually get the following error.

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.
avrdude: ser_open(): can't open device "\\.\COM12": Access is denied.


Failed uploading: uploading error: exit status 1

The Com port value might change depending on where I have it plugged in or my sequence of testing.

Right now, the Bootloader shows as Com 12, but after bootload it shows as Com 8.

Normally after Bootload, the LED just blinks (by default), sometimes I do something (unknown what) and it stops blinking after Bootload. I have followed the Bootloader replacement. Arduino Leonardo Bootloader Replacement - iFixit Repair Guide
Which brings it back to a mode where it just blinks after Bootloading.

I have tried both Arduino as ISP and Arduino as ISP (Atmega32U4) with the same results.

The vendor at this point has suggested holding the reset button and releasing just after the program compiles. It's extremely hard to time this correctly as it happens so quick, but also doesn't make any difference.

Any help would be greatly appreciated.

Is serial monitor open in IDE 2.0.4? If yes, close it.

@sterretje Thanks, I saw that earlier today. Unfortunately it is NOT open. I wish it was that simple.

Do you have a terminal program installed (realterm, coolterm, putty, ...)? You can use that to check if the issue relates to the IDE or to something else.

  1. Open the terminal program.
  2. Double tap the reset button on your board.
  3. In the terminal program, open a connection on the bootloader port (COM8 from your example); you have about 8 seconds. baud rate does not matter, you only want to know if you can connect.

If you don't get an error while opening that you can't connect, the issue relates to the IDE.

@sterretje If I'm doing it correctly, I cannot connect with a Terminal. Tried both Realterm and Coolterm. Bot see the port but can't access it. realterm showed "Port Closed", Coolterm shows "Disconnected"

Both gave "An error occured" Access Denied.

So seems to be something with the board itself. Or the port on the board.

I did see something about using another board to upload a program, but then the bootload would be wiped out.

My mistake, you need to use COM12 in the terminal program (the bootloader port). Apologies for that.

Check with device manager which port it actually should be.

@sterretje I was able to get Com12 to connect if I timed everything just right. I could never get Com8 to connect with RealTerm. I think it's something with the timing of the uploader. There has to be an easier way.

Unfortunately the only advise from the Vendor was to click reset right after "Compile completed" but that's super hard to time.

You can only connect to the non-bootloader port (COM8) if it's not open in another application (e.g. the IDE).

Because you can connect to COM12 using a terminal program after invoking the bootloader, the issue is IDE 2.0 related. I can't get the detection right in IDE 2.0 if I manually reset a Leonardo.

My advise is to install IDE 1.8.19 (zip version, preferably with portable install) and use that for uploads. Or run avrdude manually; it's a bit of a slap as you have to reset the board and run avrdude with the correct COM port.

@sterretje will try again later, but initially that doesn't seem to work either.... Will try the Manual mode.

I just feel like when you reset the board and it's in Bootload, it's not there long enough to upload. It then moves on the the next stage and the Com# changes.

What does not want to work either? Using 1.8.19?

Once a board is in bootload mode, it waits for N seconds for the actual upload (commands and data) to start. Once that upload is started, the N seconds are ignored.

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