Problems uploading to Arduino Uno

Not entirely sure if I am posting n the correct forum, so I apologize in advance if I picked the incorrect one.

I am having problems uploading a sketch to the Arduino Uno from PlatformIO. I can upload from the Arduino IDE without error, 100% of the time.

What is happening with PlatformIO, is that the majority of the time, it gives me an access denied error accessing the com port the Arduino is connected to. Retrying over and over, and eventually it works.

Have tried different cables and USB ports, with no change in the way it works. I have rebooted the computer, as well as reset the Arduino, again with no change.

Resource manager doesn’t show anything using the com port.

When trying to upload the TX light on the Arduino flashes before I get the access denied message.

Here is a short video showing what it is doing.

Any help fixing this would be greatly appreciated, as I like PlatformIO, over the Arduino IDE, and don’t want to have to switch back :frowning:

Thanks for any help you can provide!
-Larry

Hm, the error message for “Access denied” is rather generic, but mostly because another program (like the [Arduino] serial monitor) is using the COM port, or because some antivirus is blocking access to it.

Also if your Uno board is a clone with a CH340 chip on it, make sure to install the latest drivers.

There are some threads about it with generic solution hints, like

  • trying different USB cables and ports on the computer
  • reconnecting the device
  • rebooting
  • updating drivers
  • changing the COM port number of the device in the device manager (here)
  • kill eventually running avrdude.exe zombie processes hogging the port (here)
  • temporarily disable additional antivirus software, if installed
  • add PlatformIO tools / folders to the exception list of Windows Defender, especially the process name avrdude.exe
  • check if the behavior occurrs with other boards as well

I will try some of these ideas. My board is a clone, but it is using the Atmega16U2 chip, not the CH340.

I’ll post another reply if any of these ideas work.

Thank you for taking the time to reply!

-Larry

Ok, looks like this has fixed the issue. I manually changed the com port allocated to the Uno from COM5 to COM10, and 4 successive attempts to upload a sketch were all successfull.

I really appreciate your help on this. I was getting very frustrated with it :slight_smile:

Thanks again,
-Larry

Glad to hear it helped.

If the problem occurrs again after a restart (or starting some other software), it will be a strong indication though that some program is hogging all available COM ports in the system (and just hasn’t yet caught wind of the COM port number change that you just did), so be wary of that.

I will. Thank you very much for your help on this!

-Larry

You were on point. It has started giving me access denied on Com10 now as well, so back to the drawing board to try to figure out what is holding that port, without showing up in resource manager :frowning:
-Larry

Have you checked stuff regarding the antivirus?

Also with this and this information I was able to check what program is using my COM port. E.g., if I plug in my Arduino Uno and execute the reg query command in a cmd.exe…

C:\>REG QUERY "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM"

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
    \Device\Serial0    REG_SZ    COM1
    \Device\USBSER000    REG_SZ    COM14

I know my Uno (COM14) is the device handle \Device\USBSER000. Then using Process Explorer per above article I search for programs holding that device handle…

which is correct since I was opening the serial port using hterm.

So if that doesn’t yield any results for you, it could still be the antivirus.

Ok, gave this a shot.

Here is what I am coming up with.

So it doesn’t show anything using the port, and I confirmed that I was getting an access denied error both before and after I took these screenshots.

As for Anti Virus, I am running MalwareBytes paid version on the computer, and it looks like the Ransomware protection may be the culprit. First I turned off all protection, and found that I was able to upload multiple times without issue, then turning the protections back on, one at a time, it still uploaded each time without issue, until I turned on the Ransomware protection. Then it started failing again. Ultimately, I found that I could have everything except ransomware protection turned on and upload fine. It’s only when the Ransomware protection is active that I have the problem. So it looks like you have definitely pointed me in the proper place.

So, now I just need to pour through MalwareBytes and see if I can figure out how to make it leave the com ports alone, while still providing protection against ransomware, if that is even possible :slight_smile:

I really appreciate all the help you have been on this issue for me. It is always great to find a community that is willing to help each other out.

Thanks,
-Larry