I have a simple Python code that connects to an Arduino board using serial communication through the serial port.
I am using the Python library "pyserial". It is Python2.7
I create a connection basically doing something like
ser = serial.Serial("/dev/ttyACM0", 115200)
After this I send commands to my arduino board using serial.write. I have a homemade firmware that reads the commands and moves some motors.
This code is working, it is working at the moment. Though I day I connect and disconnect several times to do stuff with my robot. I always flush everything (serial.flush). At some point it simply fails. It seems to connect, but is not executing anything. It's like if at some point the serial port is corrupted.
Once I reboot the computer, everything works fine.
Any idea how can I fix it without rebooting the computer?
Unplugging the USB cables don't work.
A problem that I had was that I did not close the serial connection:
ser.close()
This lead to the point that the python process did not close and blocked any access to the serial connection. It could be that pyserial keeps the process from dying since it starts a thread in the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With