How to get a unique ID for each Arduino

心已入冬 提交于 2021-01-29 04:50:35

问题


I use two Arduino Nano, and want to change their name as listed in /dev, because currently they are always ttyUSB<NUMBER>.

How can I get a unique serial number to create a udev rule?

I tried to get it via udevadm, but it returns the same serial ID for both Arduinos.

/var/log: udevadm info -a -n /dev/ttyUSB0 | grep '{serial}'
    ATTRS{serial}=="0000:00:14.0"

回答1:


Arduino Nano is based on ATmega328 which does not have a built-in USB controller. The USB connector on the board is connected to an external USB-to-TTL converter IC. So all USB device parameters you see on the PC side belong not to the Arduino itself but to the USB chip.

Many of those chips can be separately programmed with unique serial numbers. Alternatively you could just use your PC port numbers that you plug your Arduino boards into as the unique identifiers instead.

The udevadm command you tried shows "serial" of the USB controller in your PC that your Arduino board is plugged into, rather than the serial of USB chip on the Arduino board.

Instead do udevadm info -n /dev/ttyUSB0 -q all. The line with the serial number would look like E: ID_SERIAL_SHORT=12345678. If that line is missing or indeed contains the same number for all your boards - use this udev rule to assign unique aliases based on the USB port number:

ACTION=="add", KERNEL=="ttyUSB*", SYMLINK+="arduino/tty-%s{../busnum}-%s{../devpath}"


来源:https://stackoverflow.com/questions/41164060/how-to-get-a-unique-id-for-each-arduino

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!