4

I have a Neato XV-* lidar unit, connected with a Sparkfun FTDI chip, and an Arduino Uno. They show up as /dev/ttyUSB0 and /dev/ttyUSB1, unpredictably unassigned.

So, I wrote /etc/udev/rules.d/80-arduinouno.rules:

SUBSYSTEM=="tty",
ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86",
MODE="0666",
OWNER="pi", GROUP="pi",
SYMLINK+="arduinouno"

... and /etc/udev/rules.d/90-neatolidar.rules:

SUBSYSTEM=="tty", ENV(ID_SERIAL_SHORT)=="AL01OTZS",
ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", ATTRS{serial}=="AL01OTZS",
MODE="0666", OWNER="pi", GROUP="pi",
SYMLINK+="neatolidar"

idProduct and idVendor were taken from the first line of

udevadm info --attribute-walk --name=/dev/ttyUSB1 | grep idProduct

and

udevadm info --attribute-walk --name=/dev/ttyUSB1 | grep idVendor

respectively, cross-referenced with the output of lsusb. IS_SERIAL_SHORT was taken from the output of

udevadm info -q all -n /dev/ttyUSB0 | grep ID_SERIAL

or

udevadm info --attribute-walk --name=/dev/ttyUSB0 | grep {serial}

but, while this command worked for the FTDI/lidar, it only gave an ID_SERIAL, not an ID_SERIAL_SHORT, for the Arduino.

When I do a sudo service udev restart, then try plugging and unplugging the devices while monitoring watch 'ls -lah /dev | grep ">"', I see symlinks appearing for both arduinouno and neatolidar to whichever ttyUSB* was plugged in last. That is, at the moment, I see both arduinouno -> ttyUSB1 and neatolidar -> ttyUSB1. But if I unplug and replug ttyUSB0, both will switch to that.

How can I get my udev rules to distinguish these two devices, and only fire when the correct device is detected?

If it matters, this is on a Raspberry Pi 3 running Raspbian Jessie. The Arduino is connected directly to the RPi, while the FTDI is connected to a cheap yellow EagleTec 4-port USB hub.

migrated from askubuntu.com Dec 29 '16 at 21:00

This question came from our site for Ubuntu users and developers.

2

My reputation doesn't appear to be high enough to allow a comment.

Aside: I use the following bash script to reload my udev rules and retrigger, so I don't even need to unplug and replug the device:

#!/bin/bash

sudo udevadm control --reload-rules
sudo udevadm trigger
  • Once you have sufficient reputation (50) you will be able to comment on any post. In the meantime you can gain reputation by asking your own questions or providing answers on subjects you know. This however does look like a possible answer, it is just not phrased at such? Could edit to make it read like a possible answer? – Stephen Rauch Jan 24 '17 at 1:25
  • I didn't know about the udevadm trigger; that is useful, thanks. – tsbertalan Jan 25 '17 at 1:15
1

Running sudo udevadm control --log-priority=info, then watching the output of tail -f /var/log/syslog, I noticed some errors.

Jan 23 21:22:05 raspberrypi systemd-udevd[1587]: invalid key/value pair in file /etc/udev/rules.d/80-arduinouno.rules on line 1,starting at character 17 ('\n') Jan 23 21:22:05 raspberrypi systemd-udevd[1587]: invalid key/value pair in file /etc/udev/rules.d/80-arduinouno.rules on line 2,starting at character 50 ('\n') Jan 23 21:22:05 raspberrypi systemd-udevd[1587]: invalid key/value pair in file /etc/udev/rules.d/80-arduinouno.rules on line 3,starting at character 12 ('\n') Jan 23 21:22:05 raspberrypi systemd-udevd[1587]: invalid key/value pair in file /etc/udev/rules.d/80-arduinouno.rules on line 4,starting at character 23 ('\n')

and

Jan 23 21:23:01 raspberrypi systemd-udevd[1646]: unknown key 'ENV(ID_SERIAL_SHORT)' in /etc/udev/rules.d/90-neatolidar.rules:1
Jan 23 21:23:01 raspberrypi systemd-udevd[1646]: invalid rule '/etc/udev/rules.d/90-neatolidar.rules:1'
Jan 23 21:23:01 raspberrypi systemd-udevd[1646]: invalid key/value pair in file /etc/udev/rules.d/90-neatolidar.rules on line 2,starting at character 77 ('\n') Jan 23 21:23:01 raspberrypi systemd-udevd[1646]: invalid key/value pair in file /etc/udev/rules.d/90-neatolidar.rules on line 3,starting at character 36 ('\n')

From this in inferred (1) that my ENV(ID_SERIAL_SHORT) rule wasn't working, and (2) I should have no newlines. So, I changed to the following one-line .rules files:

/etc/udev/rules.d/80-arduinouno.rules:

SUBSYSTEM=="tty", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", MODE="0666", OWNER="pi", GROUP="pi", SYMLINK+="arduinouno"

and /etc/udev/rules.d/90-neatolidar.rules:

SUBSYSTEM=="tty", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", ATTRS{serial}=="AL01OTZS", MODE="0666", OWNER="pi", GROUP="pi", SYMLINK+="neatolidar"

After reboot (or maybe just sudo service udev restart and/or sudo udevadm control --reload), this seems to work.

  • you can escape the newlines with a backslash (e.g. like this) – don_crissti Jan 23 '17 at 21:35
  • @don_crissti Good to know; thanks. I might try this later, but, as these rules files are intended to be created with a HEREDOC in a bash script (goo.gl/6O6Eeg) that modifies a disk image file (and so is slow to test), I'll just avoid escaping jiggerypokery, and how that might interact with bash, for now. – tsbertalan Jan 23 '17 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.