Arduino disconnecting at upload This problem doesn't seen to be very common around the Arduino community.

Basically, what's happening is that as soon as I click the upload button, the Arduino IDE tells me that my Arduino board is not connected. What's strange though is that the python application ino is able to upload my code just fine, so my only guess is that there is something wrong with the IDE itself.

Here's a copy of the error message I am getting at the time of uploading the sketch:


  Binary sketch size: 444 bytes (of a 32,256 byte
  maximum)processing.app.SerialException: Error opening serial port
  '/dev/ttyACM1'.at processing.app.Serial.(Serial.java:178)at
  processing.app.Serial.(Serial.java:77)at
  processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)at
  processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:174)at
  processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)at
  processing.app.Sketch.upload(Sketch.java:1671)at
  processing.app.Sketch.exportApplet(Sketch.java:1627)at
  processing.app.Sketch.exportApplet(Sketch.java:1599)at
  processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)at
  java.lang.Thread.run(Thread.java:744)Caused by:
  gnu.io.UnsupportedCommOperationException: Invalid Parameterat
  gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:213)at
  processing.app.Serial.(Serial.java:163)... 9
  moreprocessing.app.debug.RunnerException: Error opening serial port
  '/dev/ttyACM1'.at
  processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)at
  processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:174)at
  processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)at
  processing.app.Sketch.upload(Sketch.java:1671)at
  processing.app.Sketch.exportApplet(Sketch.java:1627)at
  processing.app.Sketch.exportApplet(Sketch.java:1599)at
  processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)at
  java.lang.Thread.run(Thread.java:744)


I am expecting to hear a few questions regarding this issue, so I'll go ahead and answer all the questions I can think of.


  Is this the first time you trying to connect to the Arduino from this computer?


No. In fact, I was able to upload the same source code just fine less than two hours ago.


  Did you try a different USB cord?


Yes, I did.


  Can you upload the source code from a different computer?


Yes, I can.


  Have you tried removing and reinstalling the IDE?


Yes, I have.


  Have you tried a different USB port?


Yes, I have.

What seems to be the problem here?
First of all, you must test if the device that you are trying to access, actually exists. The device file may change when you replug the Arduino. The easiest way to accomplish that is to find the device name in the error message, in this case /dev/ttyACM1. Then check two things:


Does the device file exist in  the /dev tree? ls -l /dev/ttyACM*
Is the Arduino IDE configured to use the correct device? Check under Tools => Serial Port.


Maybe another application is using the device. When working on Linux, you can verify this with the following commands:

$ lsof /dev/ttyUSB0
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF      NODE NAME
avrdude 7356   jippie    3u   CHR  188,0      0t0 266450197 /dev/ttyUSB0


or

€ fuser /dev/ttyUSB0
/dev/ttyUSB0:         7356


Where of course you have to replace /dev/ttyUSB0 with the device file as mentioned in the error message. In case of this question /dev/ttyACM1, but do notice that the number can change when you unplug the board for a moment and then replug it.

In both results, the 7356 is the PID of the process that is locking the device. In my example I was reading flash from the command line, so the output for your specific situation will be different. To identify the process, you can use:

$ ps -fp 7356
UID      PID  PPID  C STIME TTY          TIME CMD
jippie  7698 28116  1 20:34 pts/8    00:00:00 avrdude -patmega1280 -carduino -P/dev/ttyUSB002 -b57600 -D -Uflash:r:/tmp/flash:i


or a more portable command:

$ ps -ef | grep 7356
jippie  7698 28116  1 20:34 pts/8    00:00:00 avrdude -patmega1280 -carduino -P/dev/ttyUSB002 -b57600 -D -Uflash:r:/tmp/flash:i