USB aliases – Multiple Arduinos on an OpenWRT device

dev
If you want to add multiple Arduino or other USB to UART devices to your Openwrt router you will need to symlink them so that the devices don’t mix up while the router reboots.

Our objective is to symlink /dev/ttyUSB0, /dev/ttyUSB1 … to /dev/device0, /dev/device1… In our example we will use a setup with an USB 2.0 hub, and an Arduino. USB 2.0 hub solves a bug in the usb 1.0 connection between the arduino and OpenWRT.
First we need to find out idVendor,idProduct and bcdDevice for each connected device, we can do that with “lsusb -v”:

idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00

The first zeros are ignored and we use:

PRODID=”403/6001/600″

And this is the whole script:

PRODID=”403/6001/600″
SYMLINK=”arduino”

if [ “${PRODUCT}” = “${PRODID}” ];
then if [ “${ACTION}” = “add” ];
then
DEVICE_NAME=$(ls /sys/$DEVPATH | grep tty)
if [ -z ${DEVICE_NAME} ];
then logger -t Hotplug Warning DEVICE_NAME is empty
exit

fi
logger -t Hotplug Device name of cp210 is $DEVICE_NAME
ln -s /dev/$DEVICE_NAME /dev/${SYMLINK}
logger -t Hotplug Symlink from /dev/$DEVICE_NAME to /dev/${SYMLINK} created
fi

fi
if [ “${PRODUCT}” = “${PRODID}” ];
then if [ “${ACTION}” = “remove” ];
then rm /dev/${SYMLINK}
logger -t Hotplug Symlink /dev/${SYMLINK} removed
fi

fi

You need to save the scripts under /etc/hotplug.d/usb/. Script names dictate the execution order so name them in this way: 20-arduino1 30-digitemp…

there is one more thing you need to enable executing the scripts: In /etc/hotplug2.rules, remove ‘^’ before ^usb$ and restart the router:

vi /etc/hotplug2.rules

$include /etc/hotplug2-common.rules

SUBSYSTEM ~~ (^net$|^input$|^button$|usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
exec /sbin/hotplug-call %SUBSYSTEM%
}

DEVICENAME == watchdog {
exec /sbin/watchdog -t 5 /dev/watchdog
next-event
}

reboot&exit

And now you should have /dev/arduino ready for use!

One thought on “USB aliases – Multiple Arduinos on an OpenWRT device

  1. Pingback: Cheap tweeting RFID home security/automation system V1.5 | labOS - otvoreni multimedijski laboratorij

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s