Leonardo - Unable to upload sketch (error message in post)

Windows 10 - Arduino 1.8.13

I'm unable to get a sketch loaded onto my micro controller. I've posted my error below. I'm assuming it is a com error with the device. I'm not very familiar with arduino but I am pretty familiar with serial comms. Im assuming arduino defaults to 9600 8N1? I've tried changing the port for controller, different USB ports, different USB cable and still haven't had any success. Any advice would be helpful. The sketch I'm loading is a Seesaw Trellis sketch I found on this website. I cant write code to save my life. I'm trying to assemble this little device for my sister.

Thanks

processing.app.debug.RunnerException
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
	at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
	at processing.app.SketchController.upload(SketchController.java:732)
	at processing.app.SketchController.exportApplet(SketchController.java:703)
	at processing.app.Editor$UploadHandler.run(Editor.java:2055)
	at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port 'COM9'.
	at processing.app.Serial.touchForCDCReset(Serial.java:107)
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
	... 5 more
Caused by: jssc.SerialPortException: Port name - COM9; Method name - openPort(); Exception type - Port busy.
	at jssc.SerialPort.openPort(SerialPort.java:164)
	at processing.app.Serial.touchForCDCReset(Serial.java:101)
	... 6 more

Either there is more to the report of you need to turn on VERBOSE for upload in the IDE preferences.

Don't try to change any COM settings in windows as you may also force errors that way too !

You neglected some other details too such as the sketch.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

I enabled the VERBOSE and this is the error I was given.

Sketch uses 10196 bytes (35%) of program storage space. Maximum is 28672 bytes.
Global variables use 532 bytes (20%) of dynamic memory, leaving 2028 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port COM9
processing.app.debug.RunnerException
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
	at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
	at processing.app.SketchController.upload(SketchController.java:732)
	at processing.app.SketchController.exportApplet(SketchController.java:703)
	at processing.app.Editor$UploadHandler.run(Editor.java:2055)
	at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port 'COM9'.
	at processing.app.Serial.touchForCDCReset(Serial.java:107)
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
	... 5 more
Caused by: jssc.SerialPortException: Port name - COM9; Method name - openPort(); Exception type - Port busy.
	at jssc.SerialPort.openPort(SerialPort.java:164)
	at processing.app.Serial.touchForCDCReset(Serial.java:101)
	... 6 more

Also, here is the sketch.

/* This example shows basic usage of the NeoTrellis.
  The buttons will light up various colors when pressed.
  The interrupt pin is not used in this example.
*/

#include "Adafruit_NeoTrellis.h"

Adafruit_NeoTrellis trellis;

//define a callback for key presses
TrellisCallback blink(keyEvent evt){
  // Check is the pad pressed?
  if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
    trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
  } else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
  // or is the pad released?
    trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
  }

  // Turn on/off the neopixels!
  trellis.pixels.show();

  return 0;
}

void setup() {
  Serial.begin(9600);
  //while(!Serial);
  
  if (!trellis.begin()) {
    Serial.println("Could not start trellis, check wiring?");
    while(1);
  } else {
    Serial.println("NeoPixel Trellis started");
  }

  //activate all keys and set callbacks
  for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
    trellis.registerCallback(i, blink);
  }

  //do a little animation to show we're on
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
    trellis.pixels.show();
    delay(50);
  }
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, 0x000000);
    trellis.pixels.show();
    delay(50);
  }
}

void loop() {
  trellis.read();  // interrupt management does all the work! :)
  
  delay(20); //the trellis has a resolution of around 60hz
}


/******************************************/

// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  return 0;
}

From what I’m understanding, this is the important bit for the serial comms to work correctly.

void setup() {
  Serial.begin(9600);
  //while(!Serial);

I would try the following

Disconnect the Arduino from the PC
2)
Reboot PC; this should get rid of the busy port
3)
Load an innocent sketch (e.g. blink) in the IDE; make sure Leonardo is selected, COM port is not really relevant for this (as far as I know).
4)
Press reset on the Leonardo and keep it pressed
5)
Connect the Leonardo to PC, still keeping the reset pressed
6)
Start the upload
7)
When the IDE reports the memory usage, release the reset button of the Leonardo

Can you provide a link to the Neotrellis library? I tried to find it but failed to find the correct one.

Notes
1)
Keeping the reset pressed and releasing it should prevent the port from being busy; it also performs the same function as the Forcing reset using 1200bps open/close on port COM9.
2)
If you have another Arduino, you can connect that first and select that serial port in the IDE; to my knowledge the port is not critical for the upload.
3)
Other debugging:
Check in device manager what it says for the Leonardo; usually it will say Arduino Leonardo with a COMx; after pressing reset and releasing it, it should say Arduino Leonardo Bootloaderwith a COMy.

sterretje:
I would try the following

Disconnect the Arduino from the PC
2)
Reboot PC; this should get rid of the busy port
3)
Load an innocent sketch (e.g. blink) in the IDE; make sure Leonardo is selected, COM port is not really relevant for this (as far as I know).
4)
Press reset on the Leonardo and keep it pressed
5)
Connect the Leonardo to PC, still keeping the reset pressed
6)
Start the upload
7)
When the IDE reports the memory usage, release the reset button of the Leonardo

Can you provide a link to the Neotrellis library? I tried to find it but failed to find the correct one.

Notes
1)
Keeping the reset pressed and releasing it should prevent the port from being busy; it also performs the same function as the Forcing reset using 1200bps open/close on port COM9.
2)
If you have another Arduino, you can connect that first and select that serial port in the IDE; to my knowledge the port is not critical for the upload.
3)
Other debugging:
Check in device manager what it says for the Leonardo; usually it will say Arduino Leonardo with a COMx; after pressing reset and releasing it, it should say Arduino Leonardo Bootloaderwith a COMy.

Trying your suggested method, this is the error I receive. This was trying to upload the "Blink" sketch.

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.
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {COM10, } => {COM10, }
Found upload port: COM10
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM10 -b57600 -D -Uflash:w:C:\Users\AMDpc\AppData\Local\Temp\arduino_build_570530/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 "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM10
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
avrdude: ser_open(): can't open device "\\.\COM10": Access is denied.



avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This is what I'm seeing in device manager.

Here is the link to the sketch I'm using.

I don't have another Arduino to try, unfortunately. Unless I'm just unlucky enough to have three bad cables I'm not sure what it could be. In my experience if a cable is bad I usually don't see anything in device manager.

If you don't see an Arduino Leonardo bootloader in device manager after pressing and releasing reset, (I suspect that) the bootloader is gone. To fix that you need a real programmer or another Arduino that you can use as a programmer.

Note: I did not ask for the sketch but for the NeoTrellis library.

Hello,
I have the same problem as mr_plyk, The only difference is that I use a Arduino Micro.
Today is the first time I used it and I’ve tried downloading the blink program, but I get the same error.
I’m also using IDE 1.8.13.

void setup() {
  // put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}


void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(5000);            
  digitalWrite(LED_BUILTIN, LOW);  
  delay(5000);            
}
Sketch uses 3958 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.
processing.app.debug.RunnerException
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
	at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
	at processing.app.SketchController.upload(SketchController.java:732)
	at processing.app.SketchController.exportApplet(SketchController.java:703)
	at processing.app.Editor$UploadHandler.run(Editor.java:2055)
	at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port 'COM3'.
	at processing.app.Serial.touchForCDCReset(Serial.java:107)
	at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
	... 5 more
Caused by: jssc.SerialPortException: Port name - COM3; Method name - openPort(); Exception type - Port busy.
	at jssc.SerialPort.openPort(SerialPort.java:164)
	at processing.app.Serial.touchForCDCReset(Serial.java:101)
	... 6 more

I’ve been monitoring the Device manager screen when resetting the Arduino Mirco, At first it says Arduino Micro Bootloader (COM 4), then when it’s booted it says Arduino Micro (COM 3)
Also when I try the start the Serial Monitor I get ‘Error opening serial port 'COM3'. (Port busy)’

Downloading the program via the web editor doesn’t make a difference.

Best Regards,


Update 30-10-2020.

Today I have tried using linux Ubuntu (on a laptop) instead of windows 10 (my desktop pc) to download the same program to my Arduino Micro. but it gives the same error.

I'm beginning to think it's a board related issue.

Hello,

I've found the issue with my Arduino Micro (and Leonardo) perhaps you have the same issue.
I found out that NZXT CAM software was the culprit who kept my com ports busy.

Once I closed NZXT CAM I could upload programs to my Micro and Leonardo.

4 Likes