Linux and serial port

Hi all,

I run Linux (Ubuntu 12.04) and usually the com port for my Arduino board is /dev/ttyACM0.

However, if I make a mistake (like switch between the Uno and the Mega) and forget to change it in the IDE, the com port gets "messed up".

If I unplug and re-plug the Arduino, it gets assigned a new com port (typically /dev/ttyACM1).

Is there any way to "clear" the locked up com port so that if I'm using /dev/ttyACM0 and "mess it up", I can run a command and "fix" the port so that I can use it again?

By the way, I am hoping for a command line solution rather than GUI.

Thank you!

-- Roger

I don't know what "messed up" means.

If the com port gets stuck open by avrdude or some other process then:

"lsof | grep <serial_port_name>" will tell you the process holding the serial port open.

Thank you for the reply.

By "messed up" I mean that /dev/ttyACM0 seems to be stuck "in use" and re-plugging in the Arduino creates the next com port in line (i.e. /dev/ttyACM1).

Now that you mention it, it seems to make sense that AVRDUDE tries to access the Arduino board, fails, then maybe doesn't terminate and keeps the port open.

I'll try lsof | grep /dev/ttyACM0 and see if that's it. Then I can kill the old process and free up the port.

Great idea. Thanks again!

-- Roger

Make your life easier. Just use "lsof | grep ttyACM".

That was actually what I was going to do! :smiley:

Thanks again!

-- Roger

FYI: You were right. AVRDUDE had the com port locked and all I had to do was find it's process number and kill it. Problem solved.

Thanks again!

-- Roger