I am using PlatformIO for programming and Arduino Mega and an Arduino Uno. I have them hooked up through serial, so I have to disconnect them from each other every time I want to program them. I also unplug them from the computer so that I don't accidentally fry them while moving wires around.
Every time I plug one or the other back in and try to program it immediately, I get this error message:
*** [upload] could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'
If I wait for about a minute and try again, then the code will be uploaded no problem. What could be causing this?
ModemManager might be the cause of your troubles. Try disabling it with, e.g. pkill -STOP ModemManager
(continue the process with -CONT
).
ModemManager is a (fantastic) piece of software that makes your 3G dongles work automagically. Because the Arduino appears as a serial modem, ModemManager tries to take control over it.
You can stop ModemManager from doing that by attaching a certain variable to your device. See the documentation for details. Essentially, create a udev rule, e.g. /etc/udev/rules.d/99-ttyacms.rules
with the following content:
ATTRS{idVendor}=="0ca6" ATTRS{idProduct}=="a050", ENV{ID_MM_DEVICE_IGNORE}="1
Of course, you need to use your IDs. Use lsusb
to find those values.
After you have created this file, reload udev with something like sudo udevadm control --reload-rules