如何为每个 Arduino 获取唯一 ID [英] How to get a unique ID for each Arduino

查看:115
本文介绍了如何为每个 Arduino 获取唯一 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用两个 Arduino Nano,并想更改 /dev 中列出的名称,因为目前它们总是 ttyUSB.

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

如何获得唯一的序列号来创建 udev 规则?

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

我尝试通过 udevadm 获取它,但它为两个 Arduino 返回相同的序列号.

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"

推荐答案

Arduino Nano 基于 ATmega328,没有内置 USB 控制器.板上的 USB 连接器连接到外部 USB-to-TTL 转换器 IC.所以你在PC端看到的所有USB设备参数都不属于Arduino本身,而是属于USB芯片.

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.

其中许多芯片可以使用唯一的序列号单独编程.或者,您可以使用您插入 Arduino 板的 PC 端口号作为唯一标识符.

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.

您尝试的 udevadm 命令显示了您的 PC 中插入 Arduino 板的 USB 控制器的串行",而不是 USB 芯片上的串行Arduino 板.

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.

改为执行udevadm info -n/dev/ttyUSB0 -q all.带有序列号的行看起来像 E: ID_SERIAL_SHORT=12345678.如果该行丢失或确实包含所有板的相同编号 - 使用此 udev 规则根据 USB 端口号分配唯一别名:

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}"

这篇关于如何为每个 Arduino 获取唯一 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆