trouble uploading on ubuntu 12.04

OS: Ubuntu 12.04 LTS
Board: Arduino Uno
IDE: latest version in Ubuntu universe 1:1.0+dfsg-9 installed via synaptic
Problem: can't upload code, something about /var/lock/

Command line dump (ran as root per tip on Troubleshooting page):

$ sudo arduino
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyACM0
Binary sketch size: 1010 bytes (of a 32256 byte maximum)
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.Serial.<init>(Serial.java:146)
	at processing.app.Serial.<init>(Serial.java:76)
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:75)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:88)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:66)
	at processing.app.Sketch.upload(Sketch.java:1664)
	at processing.app.Sketch.exportApplet(Sketch.java:1624)
	at processing.app.Sketch.exportApplet(Sketch.java:1578)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2314)
	at java.lang.Thread.run(Thread.java:679)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
	at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:213)
	at processing.app.Serial.<init>(Serial.java:136)
	... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:99)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:88)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:66)
	at processing.app.Sketch.upload(Sketch.java:1664)
	at processing.app.Sketch.exportApplet(Sketch.java:1624)
	at processing.app.Sketch.exportApplet(Sketch.java:1578)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2314)
	at java.lang.Thread.run(Thread.java:679)

I am successfully able to upload from my mac (OS 10.7.4). I was able to upload from my linux box last week using the arduino, but after a system update (possibly including a kernel update?) I started having these /var/lock issues. At first I could still upload to my arduino by running the IDE as root, but that no longer works. The code I had been trying to upload used the serial port, but now I'm just trying to upload the blink example. I successfully uploaded the blink example using my mac, but I can't upload blink from my linux computer anymore... :frowning:

You should not need to run as root. I'm using 12.04, but I only downloaded/installed the repository version. I have not run it yet. I downloaded IDE v1.0.1 from the Arduino site, and unpacked it in a local directory. Then I created a link to the arduino shell script in that directory, and moved the link to my desktop. Don't move the arduino shell script. It is "current directory" dependent.

Log in as your user (no sudo). Start a command prompt terminal. Enter this:

groups

Among many, one of the groups should be dialout. If not, you must add that group to your user.

sudo usermod -aG dialout myusername

Then you must log out and log in again for the change to work. If that is not it, let me know.

I forgot to mention that I'm running Ubuntu 12.04 LTS 64 bit. I'm not sure if the 64 bit is a problem or not.

I checked which groups my account belongs to, and dialout is definitely included.

I'm having permissions issues with my device, that's why I tried running as sudo.

I installed the 1.0.1 version from the arduino page. If I call the arduino script from the command line as my a normal user, the Arduino IDE indicates (in the bottom right corner) "Arduino Uno on /dev/ttyACM0" (which is accurate). Unfortunately, if I click Tools->Serial Port only /dev/ttyS0 is available. I see the following print out to the command line when I launch the Arduino IDE:

$ arduino
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyACM0
RXTX Error:  Unable to 					remove stale lock file: /var/lock/LCK..ttyACM0

I see the same behavior with Arduino IDE version 1.0 that I installed via Ubuntu's package manager.

If I instead call the Arduino IDE with sudo from the command line, I see the following in the command line:

$ sudo arduino
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyACM0

When I run the Arduino IDE as root from the command line, the IDE correctly indicates (in the bottom right corner) that my arduino is located at /dev/ttyACM0. Now when I go to Tools->Serial Port I see two options, /dev/ttyS0 and /dev/ttyACM0 (which is checked by default, sweet!). Unfortunately, I see the following error at the command line when I try to upload the blink example:

$ sudo arduino
Binary sketch size: 1010 bytes (of a 32256 byte maximum)
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.Serial.<init>(Serial.java:146)
	at processing.app.Serial.<init>(Serial.java:76)
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:75)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:88)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:66)
	at processing.app.Sketch.upload(Sketch.java:1664)
	at processing.app.Sketch.exportApplet(Sketch.java:1624)
	at processing.app.Sketch.exportApplet(Sketch.java:1578)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2314)
	at java.lang.Thread.run(Thread.java:679)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
	at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:213)
	at processing.app.Serial.<init>(Serial.java:136)
	... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:99)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:88)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:66)
	at processing.app.Sketch.upload(Sketch.java:1664)
	at processing.app.Sketch.exportApplet(Sketch.java:1624)
	at processing.app.Sketch.exportApplet(Sketch.java:1578)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2314)
	at java.lang.Thread.run(Thread.java:679)

This is very frustrating. What is going on? I am still able to successfully reprogram my arduino on my Mac. It looks like there is some kind of permission error on the serial port...?

On ubuntu 12.04, I have no problem for uploading to Arduino Mega (1280) through the IDE 1.0.1
The official package is still IDE 1.0… and so I can't ran it. I uninstalled this version :wink:

Don't run arduino from the terminal like that. It runs the repository version. If you want the downloaded version 1.0.1, use this:

cd /home/user/arduinodirectorywhereunpacked
./arduino

edit: or the way I do it is navigate to that directory using the GUI, right click on the arduino shell script and create a link. Then move the link to your desktop. Then double-click the link to run the new version.

Do not run as root! No sudo! If you have problems, check your user home directory. There is a hidden directory there named ".arduino" that has a "preferences.txt" file. It may have been changed to owner=root in the sudo stuff you tried. If it is, you must change it back to you as the owner.

Haha, sorry for running that incorrectly.

When I run IDE v 1.0.1, I still get a lock error when trying to open the serial port.

$ ./arduino 
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.Serial.<init>(Serial.java:178)
	at processing.app.Serial.<init>(Serial.java:77)
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
	at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:171)
	at processing.app.Serial.<init>(Serial.java:163)
	... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)

When I try to again, I get something like:

$ ./arduino 
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyACM0
RXTX Error:  Unable to 					remove stale lock file: /var/lock/LCK..ttyACM0

I took a look at ~/.arduino/preferences.txt, I am definitely still the owner with rw privileges.

Sounds like you might need to take a look at "/var/lock", and see if there is still a stale lock on that device. You may need to remove that lock as root.

I think the Arduino IDE, or maybe one of the libraries it is using, is creating the lock after I start the IDE and subsequently prevents the IDE from communicating with the serial port.

Before running the IDE, I tried the following:

$ ls /var/lock
LCK..ttyACM0  multiload-icons-PwgnzL  whoopsie
$ sudo rm /var/lock/LCK..ttyACM0 
[sudo] password for user:

Then I run the arduino IDE and try to upload Blink:

$ ./arduino 
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.Serial.<init>(Serial.java:178)
	at processing.app.Serial.<init>(Serial.java:77)
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
	at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:171)
	at processing.app.Serial.<init>(Serial.java:163)
	... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)

Gotta ask. Who is whoopsie, and why is that device locked? My IDE does not lock the arduino and leave it like that.

$ ls /var/lock
LCK..ttyACM0 multiload-icons-PwgnzL whoopsie

Did you go back and check that the device is not locked again?

Maybe this is whoopsie?
http://www.ubuntuupdates.org/package/core/precise/universe/base/whoopsie

First I checked for the lock, then removed it, then verified the lock was gone, then started the Arduino IDE, then closed the arduino IDE w/o trying to upload anything, checked for the lock, and finally started the IDE and tried to upload Blink.

Here I'm using Arduino IDE 1.0.1 from the repo.

$ ls /var/lock
LCK..ttyACM0  multiload-icons-PwgnzL  whoopsie

$ rm /var/lock/LCK..ttyACM0 
rm: remove write-protected regular file `/var/lock/LCK..ttyACM0'? y

$ ls /var/lock
multiload-icons-PwgnzL  whoopsie

$ ./arduino
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7

$ ls /var/lock
multiload-icons-PwgnzL  whoopsie

$ ./arduino
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.Serial.<init>(Serial.java:178)
	at processing.app.Serial.<init>(Serial.java:77)
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
	at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:171)
	at processing.app.Serial.<init>(Serial.java:163)
	... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
	at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:172)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1706)
	at processing.app.Sketch.exportApplet(Sketch.java:1662)
	at processing.app.Sketch.exportApplet(Sketch.java:1634)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2346)
	at java.lang.Thread.run(Thread.java:679)

How many times have you removed that lock now? How many times has it come back?

I have no idea how many times I've removed that lock, but at least 50 times.

The lock comes up every time I try to upload to my arduino. The lock is not there before I click "upload", but once I click upload I get the error about how the Arduino IDE can't open the serial port and the lock appears.

Clearly the Arduino IDE or one of its libraries is locking the serial port and preventing the IDE from talking to the device. It sure sounds like a bug in the IDE, an incompatibility between the IDE and a library on my system, or a driver issue. Any thoughts on how to debug?

Are you using the Arduno IDE from the Arduino site? I am with no problem. Or are you still using the Ubuntu version? What does the top of the Arduino IDE window say when you open it?

Mine today says "sketch_sep16a | Arduino 1.0.1". Is that what yours says? If it is the Ubuntu version, it will say so there.

I'm using Arduino IDE version 1.0.1 which is in fact indicated at the top of the IDE. This is the version I pulled off the site, not the one in the Ubuntu universe repository.

I just tried a couple uploads to a Mega on 12.04, and all worked fine. No /var/lock/ entry (except whoopsie). Maybe something about the Uno and 12.04?

Have you looked in /dev/ to see the file attributes for the arduino?

cd /dev
ls -l ttyACM*

Mine looks like this:

tim@tim-desktop:/dev$ ls -l ttyACM*
crw-rw---- 1 root dialout 166, 0 Sep 16 12:33 ttyACM0

Mine matches:

$ ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 Sep 16 09:41 /dev/ttyACM0

What happens when you start the Arduino IDE from the command line? Do you see what I see, or do we have different RXTX versions?

$ ./arduino 
Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7

This is very frustrating! I don't know what to do!

So I tried following the directions here Arduino Playground - All

Previously I had only been looking at the debian and ubuntu help.

**Do Linux find the USB? **
Whatever that means, yes, linux does:

$ dmesg | tail
[165994.229966] usb 1-1.6: USB disconnect, device number 3
[165996.470303] usb 1-1.6: new full-speed USB device number 4 using ehci_hcd
[165996.565719] cdc_acm 1-1.6:1.0: ttyACM0: USB ACM device

Setting UDEV rule
But lsusb doesn't find the device...? Arduino UNO's Product ID should be 0001, but no USB devices found via lsusb have that product ID!

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 006 Device 002: ID 11b0:6558 ATECH FLASH TECHNOLOGY 
Bus 002 Device 003: ID 046d:c315 Logitech, Inc. Classic New Touch Keyboard
Bus 002 Device 004: ID 045e:0029 Microsoft Corp. IntelliMouse Optical
Bus 001 Device 004: ID 2341:0043

SET THE PERMISSION[\b]
looks like I pass all these tests...
** **$ ls -l /dev/ttyACM0 crw-rw---- 1 root dialout 166, 0 Sep 17 18:48 /dev/ttyACM0 $ groups userName adm dialout cdrom sudo dip plugdev lpadmin sambashare $ ls -ld /var/lock lrwxrwxrwx 1 root root 9 Sep 15 19:53 /var/lock -> /run/lock $ ls -ld /run/lock drwxrwxrwt 4 root root 100 Sep 17 21:10 /run/lock** **

I have exactly the same problem, but i think it's de rxtx library, try to uninstall it.

Few months ago i uploaded without problems, recently i installed MPIDE and I install rxtx library, the MPIDE works perfect, but arduino no.

so i tried uninstalling and reinstalling arduino, arduino-core, and rxtx from the debian packages available here: Arduino Playground - Ubuntu

unfortunately, the arduino debian package doesn't see the rxtx package that I installed!

$ sudo dpkg -r arduino
[sudo] password for user: 
(Reading database ... 305279 files and directories currently installed.)
Removing arduino ...
Processing triggers for shared-mime-info ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf.index...
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...

$ sudo dpkg -r arduino-core 
(Reading database ... 305239 files and directories currently installed.)
Removing arduino-core ...

$ sudo dpkg -r librxtx-java
dpkg: warning: there's no installed package matching librxtx-java

$ sudo dpkg -i librxtx-java_2.2pre2-11_i386.deb 
(Reading database ... 304441 files and directories currently installed.)
Preparing to replace librxtx-java:i386 2.2pre2-11 (using librxtx-java_2.2pre2-11_i386.deb) ...
Unpacking replacement librxtx-java:i386 ...
Setting up librxtx-java:i386 (2.2pre2-11) ...
Processing triggers for doc-base ...
Processing 2 changed doc-base files...
Registering documents with scrollkeeper...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

$ sudo dpkg -i arduino-core_1.0.1+dfsg-6_all.deb 
Selecting previously unselected package arduino-core.
(Reading database ... 304441 files and directories currently installed.)
Unpacking arduino-core (from arduino-core_1.0.1+dfsg-6_all.deb) ...
Setting up arduino-core (1:1.0.1+dfsg-6) ...

$ sudo dpkg -i arduino_1.0.1+dfsg-6_all.deb 
Selecting previously unselected package arduino.
(Reading database ... 305240 files and directories currently installed.)
Unpacking arduino (from arduino_1.0.1+dfsg-6_all.deb) ...
dpkg: dependency problems prevent configuration of arduino:
 arduino depends on librxtx-java (>= 2.2pre2-3); however:
  Package librxtx-java is not installed.
dpkg: error processing arduino (--install):
 dependency problems - leaving unconfigured
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf.index...
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...
Processing triggers for man-db ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for shared-mime-info ...
Errors were encountered while processing:
 arduino

what's going on?