PlatformIO can't push code to my Mayfly

I’m getting the following error when I try to upload code from PlatformIO to my EnviroDIY Mayfly data logger.

avrdude: ser_open(): can’t open device “\.\COM4”: Access is denied.

I understand from others’ comments that this usually means that something else is using that COM port. However, if I use the Arduino IDE, it is able to upload programs without issue. I can’t see anything else using the port but maybe I just don’t know the right place to look.

I’ve tried updating all the apps to the latest versions. I’ve restarted all the hardware. I’ve started over with clean code. I just don’t know where to even start debugging this. Any help would be greatly appreciated.

Well something’s gotta use the COM port. Do you have a PIO serial monitor open?

Also, open the windows resource monitor. In the CPU tab, select all proceses, then in the “Associated Handles” search for “Serial”.

For example, when I use HTerm to open COM1, the HTerm.exe process has a handle on \Device\Serial0.

Or when I open it with COM1 115200, it shows the python.exe process

So what process does it show for your Serial3 device?

Thanks for responding, maxgerhardt.
The screenshots you sent don’t look like the task manager I have for Windows.
But your questions led me to look deeper into PIO’s serial monitor.
Since the error I received trying to push something to the card showed that it autodetected COM4, I thought that was set correctly. But inside the serial monitor, PIO was looking for COM3. Looks like this mismatch caused it to flake out.
I included the “upload_port” command in my ini file with a direction for COM4 and it seems to work now.

Should have posted about my issue sooner rather than banging my head against for a long time.

Scratch that.
It worked once. But when I tried to push a different script to the card, it gave me the same access denied message.
Back to square one.

I finally found that Resource Monitor you mentioned and was able to do a search for Serial but it didn’t turn up anything useful. There was “serialization” in two hits but nothing about a serial port.
So I can’t see anything that is currently using COM4.

1 Like

Can you rerun the search (deselect and reselect all processes, press refresh button in the “associated handles” search bar) right after an upload has failed? The PIO serial monitor is off at this point, right?

After an upload fails, are you still able to connect to the COM port with a program like HTerm or does it also give an error?

Have you also tried different USB ports or cables?

I don’t have any experience with HTerm or similar software. I can download and try to figure that out.

I just tried my setup in the other USB port my machine has and it allowed me to push a sketch to the board. But just like before, when I try to push a different one it then says it doesn’t have access. The PIO serial monitor is closed and I am stuck again. I even tried switching back to the other USB port to see if I could just alternate but that didn’t work either.

I strongly believe there’s a bug in PlatformIO. I am having the exact same problem where PlatformIIO is returning Access Denied for the COM port it is to use for uploading.
I know it is not an access contention issue with another application as I can establish a Putty session with the affected COM port. I even verified Putty will generate an error if I already have a connection by opening yet another Putty session.
I think something else is going on and POI is AssUMeing that it is an access denied error.