Friday, July 12, 2013

Using Arduino Leonardo under Linux

For work, we've developed a lot of test and manufacturing gear that uses Arduino as the controller. Recently, I started using Leonardo (rather than Uno) as the base. It's all running well, until we try to connect it to the Linux servers that we use in manufacturing. They're running CentOs 5.3, and they don't see the serial port on the board. That makes them just about useless.

Hunting around on the web only turned up the fact that the latest version of Ubunu (13.04) did work with Leonardo, so that points to a driver problem.

When Leonardo first powers on, the boot loader looks like a serial port, and comes up at /dev/ttyACM0. If no one has tried to download new code before the timeout expires, the board resets the USB interface, and comes back with a multi-endpoint device. The first is a HID, and is recognized as a Mouse/Keyboard. The second is a cdc_acm device, but with a VID:PID that the older cdc_acm drivers don't recognize. The solution is to give them an update.

If you're a command line type, you can enter

echo 0x1b4f 0x9204 > /sys/bus/usb/drivers/cdc_acm/new_id

If you prefer the automagical solution, create a file /etc/udev/rules.d/46-arduino.rules, and put the following two lines in it:

BUS=="usb", SYSFS{idVendor}=="1b4f", SYSFS{idProduct}=="9204", RUN+="/sbin/modprobe cdc_acm"
BUS=="usb", SYSFS{idVendor}=="1b4f", SYSFS{idProduct}=="9204", RUN+="/bin/sh -c 'echo 0x1b4f 0x9204 > /sys/bus/usb/drivers/cdc_acm/new_id'"


Reboot, and you should be all set.