Tag Archives: Arduino

Can’t open device "\\.\COM4": Access is denied error when uploading a sketch from Arduino IDE

I’m sure that everyone who has ever tried to upload a sketch from the Arduino IDE has seen this error message:

avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.

The number of the serial port can be different, but the error is the same.

Basically (in simplified form) this error means that the USB port is in use by another application in your computer, so the Arduino IDE cannot use it to upload your sketch. It is important to understand that this error has nothing to do with Arduino, the access to the serial ports are controlled by the operating system.

Tip #1: Check your port in Device Manager

Open Device Manager and check that your IoT device appears in the Ports (COM & LPT) section. Note the number of the port (in my case COM4):

arduino-serial-port-in-device-manager

Tip #2: Check your port in the Arduino IDE

Open Arduino IDE and check in the Tools –> Port menu that you are trying to upload to the port you have seen in the Device Manager. The Arduino IDE is quite good to detect connected devices, but in case you have multiple devices connected at the same time this is definitely worth to check:

arduino-port-selection

Tip #3: Close other programs

Try to close any programs that may use this port. Unfortunately I’m not aware of any tools that could list which app is locking a particular port (if you do, please share in the comments), so you have to think. Basically any app can be the culprit that communicates with devices, and unfortunately not only apps, but device drivers also. For example some Bluetooth drivers are reported to lock COM ports even before a device is connected.

In my experience the following apps are often causing this problem:

  • Code editors: Do you have other open Arduino IDEs, Visual Studio Code instances or apps that you use to create and upload your code open?
  • Terminal monitors: Do you have a terminal monitor connected? Sometimes they are separate apps (like Termite) or built into code editors (like in Arduino IDE or in Visual Studio Code).
  • Apps and drivers for other devices: Do you have other devices connected to your computer via USB or Bluetooth, e.g. a printer, a vinyl cutter or a 3D printer?

Tip #4: Rename the port

If none of the above works you can rename the port, and most of the time this is what fixes the issue for me.

1. Open Device Manager and navigate to the Ports (COM & LPT) section (see the screenshot above).

2. Right click your COM port and select Properties.

3. In the  Properties window first click Change settings to switch to administrator mode, then navigate to the Port Settings tab:

arduino-port-properties

4. In the Port Settings tab click the Advanced button:

arduino-port-settings

5. In the Advanced Settings window select a new COM Port Number:

arduino-port-advanced-settings

Click OK and close all Device Manager windows. Windows may ask you to restart your computer, but in my experience the Arduino IDE is quite smart to detect port changes immediately.

 

Did this help you? What other tricks do you have when uploading a sketch fails?

Programmer Is Not Responding error when uploading a sketch from Arduino IDE

I recently ordered an Arduino Nano and when I tried to upload a sketch from the Arduino IDE I received the following error:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x9f

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x9f

...

avrdude: ser_send(): write error: sorry no info avail
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Unfortunately the recommended page did not help. Although there are forum posts about devices that were delivered without a booloader, I definitely did not want to mess with burning it. The loop-back test seemed to be a good idea, but in the end it turned out that the solution is very simple: selecting the ATmega328P (Old Bootloader) from the Tools –> Processor menu fixed the problem:

arduino-nano-programmer-is-not-responding-not-in-sync-fix

If this does not fix the problem for you, I recommend checking this instructable for more tips: https://www.instructables.com/A-solution-to-avrdude-stk500getsync-not-in-syn/