I’ve got a 64 bit Ubuntu 12.04 installation and wanted to get Java, via Netbeans, to interface with my Arduino Uno. The 64bit rxtx libraries allow that but following the standard installation guide results in the Arduino IDE no longer being able to find the Uno. Having dumped 8-12 hours of my existence into trying to get them simultaneously to work and finally managing it I thought I’d post here with the sequence, both so others can avoid the problems I had and perhaps for someone to iron out the last problem I have (which is not a fatal one). There may well be a similar guide somewhere but I couldn’t find it while Googling so it’s not easy to find. Also, this is not a terribly elegant way but it works and frankly that’s all I care about.
- Install NetBeans. I don’t know how to do this with Eclipse, I haven’t ever used it.
sudo apt-get install netbeans
- Make a directory rxtx in /usr/lib
sudo mkdir /usr/lib/rxtx
cd /usr/lib/rxtx sudo wget http://www.cloudhopper.com/opensource/rxtx/ch-rxtx-2.2-20081207-linux-x86_64.zip sudo wgethttp://rxtx.qbang.org/pub/rxtx/rxtx-2.2pre2-bins.zip
- Install zip if you haven’t got it
sudo apt-get install zip
- Decompress both zip files
sudo unzip http://www.cloudhopper.com/opensource/rxtx/ch-rxtx-2.2-20081207-linux-x86_64.zip sudo unzip http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip
- Move the librxtxParallel.so and .jar files from the 64 bit directory
sudo mv ch-rxtx-2.2-20081207-linux-x86_64/librxtxParallel.so ./ sudo mv ch-rxtx-2.2-20081207-linux-x86_64/RXTXcomm.jar ./
- Move the librxtxSerial.so from the appropriate 2.2 directory into the rxtx one,
sudo mv rxtx-2.2pre2-bins/x86_64-unknown-linux-gnu/librxtxSerial.so ./
- Clean up your rxtx folder by deleting the now unnecessary files
sudo rm -r rxtx-2.2pre2-bins sudo rm -r ch-rxtx-2.2-20081207-linux-x86_64 sudo rm *.zip
- Open up NetBeans and make a new Java project whose only file is SerialTest.java and is made of the code given here. With NetBeans you need to put ‘package serialtest;’ at the top of the file.
- Right click on the ‘Libraries’ tree in the projects list, ‘add JAR/folder’, navigate to /usr/lib/rxtx and add the RXTX.jar folder
- Right click on the project, properties, Run and then put the following in the VM options line
- Plug your Arduino in and upload some test program which prints to the serial port, such as the one found here.
- Go to /dev, where various hardware have some kind of software manifestations (at least I think that’s what the tty are…) and create a symlink between ttyACM0 and ttyUSB0
cd /dev sudo ln -s ttyACM0 ttyUSB0
- Run your NetBeans Java project and you’ll hopefully get something like the following output
run: WARNING: RXTX Version mismatch Jar version = RXTX-2.2-20081207 Cloudhopper Build rxtx.cloudhopper.net native lib Version = RXTX-2.2pre2 Started Hello world!
and then ‘Hello world!’ will keep appearing every second. Job done. Go forth and code.
Now to explain why this sequence of steps was necessary. Installing the standard 64bit .so and .jar files into the folders suggested by the standard installation guide causes ttyACM0 to vanish from the Arduino IDE port menu. Putting neither of them there causes NetBeans to complain it cannot find anything related to gnu.*. Putting just the .jar file causes it to complain it cannot find the Serial .so file. So I realised I needed to point the project, but not my full java installation, at the RXTXcomm.jar file, hence why it’s added in NetBeans. To get around the .so problem I tried the 32bit version, not the 64 bit version and it worked if, once again, I didn’t install it in the full java installation but rather just pointed NetBeans at it. It gives a mismatch in the version but unlike some of the other .so mismatches it isn’t fatal. Now I can upload and listen to the Uno using the Arduino IDE and listen to it using java.
I’m sure there’s a better way to do it but I am not a coder. Hell, I don’t even know any java, getting it to do simple things with the Uno was going to be my way of motivating myself to pick up the basics. I’d seen during my Googling a few others had experiences problems with this so I thought I’d post it somewhere visible so others might stumble onto it. The only additional thing is you might need to do the symlink each time you start up the computer, it seems to get wiped when you don’t have the Arduino plugged in, there’s some kind of refreshing thing going on with the /dev files due to their hardware relations. There’s probably a command line way of getting it automatically added but I don’t know it.
Hopefully this will save a few people some head bashingly frustrating hours of yelling at their computer. The Arduino is fun to play with, screwing around with multiple java file structures is not.