I connect to my Arduino board with the following Python code.
device=glob.glob("/dev/ttyUSB*")[0]
time.sleep(1)
arduino = serial.Serial(device, 115200, timeout=5)
It generally works, but somehow some other process must be accessing the board after reboot giving me the error
serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 16] Device or resource busy: '/dev/ttyUSB0'
When unplugging and replugging the USB-plug I can execute the Python code normally, without the error occuring. How can I avoid any other process blocking the port? And how do I find out the reason for this error?
In my case
was not working (it showed nothing).
What was working, however, was the following:
This gave me a list of the processes that were using my serial port and I could simply
kill
them using thePID
(corresponding to the second column in the list).You can use
to list the PIDs of the processes using the file. Alternatively, if your
fuser
command supports it you can use the-k
option to kill them.Run:
$ ps ax
You will see what process is using serial port. Kill that process. This solved it for me.