I am having trouble getting PlatformIO to upload a file to an Arduino board. It appears that it has been detected, but can’t upload. Nothing else is open that would use the port. Anyone have a solution? Thanks for the help.
Auto-detected: /dev/cu.usbserial-1420
*** [upload] could not open port /dev/cu.usbserial-1420: [Errno 16] Resource busy: ‘/dev/cu.usbserial-1420’
Are you able to upload through the Arduino IDE? Do you have a serial monitor open on that port?
The error message says resource busy. That’s an indication that the serial port is currently used by another application.
Do you have the monitor in the Arduino IDE open? Do you have some other terminal that’s currently connected? Is a previous upload attempt still stuck in the background?
The correct port is recognized but not used. How do I force it to select the correct one, although it would be great if I didn’t have to. This is the error:
*** [upload] could not open port /dev/cu.usbserial-1420: [Errno 16] Resource busy: ‘/dev/cu.usbserial-1420’
The port that it tries to use is:
/dev/cu.usbserial-1420 ‘USB2.0-Serial’
The correct port is:
/dev/cu.wchusbserial1420 ‘USB2.0-Serial’
I am able to upload with the Arduino IDE.
Ah yes, the typical CH340 chinese driver issues for Mac, they never get old (and probably never fixed). You still have the Mac serial driver installed? Did you kextunload
and rm
the old driver? (GitHub - adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver: CH340G CH34G CH34X Mac OS X driver).
The dirty option would be to force the usage of these serials by writing
upload_port = /dev/cu.wch*
monitor_port = /dev/cu.wch*
into the platformio.ini
, as it’s stated in the documentation.
The “dirty” solution works. However, is there a way to code it to allow either of two ports to be identified as upload_ports? Doing the following throws an error:
[env:uno]
platform = atmelavr
framework = arduino
board = uno
upload_port = /dev/cu.wchusbserial1420
upload_port = /dev/cu.usbserial-1420
I have two ports that I now use randomly with the Arduino IDE and would like to continue a random selection if possible.
Thanks for the help.
No, this is illegal syntax. You can only one upload_port
. But you can also supply a regex / glob pattern as I’ve shown you above with the *
so that it detects any device of them form /dev/cuwch*.
As one port is usbserial and the other is wchusb, would it have to be something like:
dev/cu.*usbserial-1420?
I think *
can also match an empty string so this expression would select both and would probably select always the first one, and not a random one. Why do you want to you want to randomly try both these ports if only one of them always works?
Just the convenience of not having to remember which port I must use for Arduino boards.
This one didn’t work:
upload_port = /dev/cu.usbserial
Nor this one:
upload_port = /dev/cu.*usbserial1720
I will probably stay with /dev/cu.wchusbserial1420 ‘USB2.0-Serial’
Thanks for the help.
Just the convenience of not having to remember which port I must use for Arduino boards.
If the port is busy… this is a driver / OS issue, not a platformio issue… so there’s no making it so that either of the two ports can be used as upload_ports on the platformio side… you’ve got to identify what is the root issue. If you do some google searches about the CH340 driver on Mac and arduino type stuff, you’ll see lots of reports about double device instances, one not working, ensuring you’re using the latest driver, using the driers from the WCH website, or even simply removing the drivers completely, and restarting, and the OS seemingly finally figures it all out. i.e.
When I experienced this problem, installing the latest driver still failed, but when I removed the old drivers and did not install anything new, it worked fine.
macos Catalina will bring major changes to USB-to-Serial drivers. The drivers will no longer run in the kernel but in user space. That’s a good move in the mid-term as it will simplify driver development and stabilize the system (the driver can no longer crash the entire system). But I wonder when the new drivers will be available and if the CH340 drivers’ quality finally improves.
Fortunately, the old drivers can still be used in Catalina, at least for one more year…
I am able to upload the code using the arduino ide but not while i use visual studio code.
serial.serialutil.SerialException: [Errno 16] could not open port /dev/cu.usbserial-1410: [Errno 16] Resource busy: ‘/dev/cu.usbserial-1410’
*** [upload] Error 1
Changes are you have two drivers for the CH340 USB-to-serial chip, resulting in two devices, and the Arduino IDE happens to pick the working one while PlatformIO picks the non-working one.
For several versions now, macOS has CH340 drivers built-in, written by Apple. So you have to uninstall the ones from WCH. They won’t work with macOS Big Sur anyway.
Check where the drivers are located:
sudo ls -l /System/Library/Extensions/usbserial.kext
sudo ls -l /Library/Extensions/usbserial.kext
Once you know the path, disable and remove them:
sudo kextunload /Library/Extensions/usbserial.kext
sudo rm -rf /Library/Extensions/usbserial.kext
With the non-functional devices gone, PlatformIO should now pick the correct device.
Same problem here: “Error message says resource busy”.
“sudo ls -l /System/Library/Extensions/usbserial.kext” reports no file there.
How can I see whether there’s :“Is a previous upload attempt still stuck in the background?”
This is my first attempt to use PIO. I closed down all Arduino stuff, where uploads were no problem at all.
Any help is very welcome!