Tag Archives: udev

Prototyping – Arduino and Ubuntu

UNO

My Arduino Uno board, via instagr.am and iPhone, on Flickr

One of those things I’ve been meaning to getting around to doing for ages is to explore this exciting new world of prototyping and hacking my own hardware devices together. A lot of my fellow eightbars and of course many of the HomeCamp community are big fans of the Arduino platform. I’ve also been dying to have a go with the MQTT client for Arduino that Nick has created (although I’ve recently also come across another platform called mbed, and MQTT has been ported to it, of which more to come soon). In fact, I’ve had one of the lovely Arduino starter kits from ::oomlout:: sitting on my desk for a while now, tempting me with its gadgetry and neatly-arranged components in a funky partitioned box… but life has been so hectic that it has taken me until today to finally crack it open!

I’m not going to spend long talking about the Arduino today, except to mention that it was unexpectedly tricky to get working under my OS of choice, Ubuntu 10.10. I’d read on Anton’s blog recently that the new UNO board (which I have) needed a firmware update in order to avoid some weirdness on the serial port, so I thought I’d go ahead and fix that first – his instructions were very clear, and the device seemed to report something, well, expected as I ran the commands. All good, or so I thought!

Português: Logotipo Arduino Uno.

Português: Logotipo Arduino Uno. (Photo credit: Wikipedia)

I installed the Arduino IDE from the Ubuntu repository and attempted to start it from the new Electronics submenu. Nothing happened. At that point I decided to try running “arduino” from the command line, and got back a Java stack trace containing java.lang.UnsatisfiedLinkError: rxtxSerial indicating an issue with some of the libraries. At that point a quick DuckDuckGo search (yes, I’m not using Google much these days) led me to an Ubuntu PPA which contained a fixed version of the IDE.

I was then able to fire up the toolkit and excitedly started looking at the Basic samples. However, as soon as I tried to upload one to the board, I got an error avrdude: stk500_recv(): programmer is not responding which suggested that the board was not being “seen” by the IDE. The only interface the toolkit recognised was ttyS0 and I knew the Arduino wasn’t there… looking in /var/log/messages I could see that it created an interface /dev/ttyACM0 when I plugged it in, but the toolkit wasn’t seeing that. I then tried creating a symlink from /dev/ttyUSB0 (where the wikis and documentation were telling me to expect the Arduino) to /dev/ttyACM0 – and presto, it worked.

Creating static symbolic links in /dev is a bit hokey these days, of course, so I moved across to udev and created a new rule for the UNO in a file called /etc/udev/rules.d/80-arduino-uno.rule

KERNEL=="ttyACM*", ATTRS{product}=="Arduino*", SYMLINK+="ttyUSB%n"

dead simple: if a new device pops up in the kernel named ttyACMsomething, and it has a USB product ID string starting Arduino (which mine does, I checked using the command usb-devices), add another symlink to it at ttyUSBsomething, thanks. Result:

Dec 21 19:18:50 agrippa kernel: [21501.209012] usb 1-1.1: new full 
speed USB device using ehci_hcd and address 17
Dec 21 19:18:50 agrippa kernel: [21501.303198] cdc_acm 1-1.1:1.0: 
ttyACM0: USB ACM device
andyp@agrippa:/etc/udev/rules.d$ ls -l /dev/ttyU*
lrwxrwxrwx 1 root root 7 2010-12-21 19:18 /dev/ttyUSB0 -> ttyACM0

That all seems to have done the trick. I’m just waiting on a couple of shields for the board, not least something that will let me connect it to a network, and then the experiments will continue! Weather-permitting the next lot of electronics should appear in the next day or so. More to come, on both Arduino and mbed hackery…

Advertisements