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

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

问题描述

我使用两个Arduino Nano,并希望更改其名称,如/dev 中所列,因为当前它们始终是 ttyUSB< NUMBER> .

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返回相同的序列ID.

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到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 命令在您的Arduino板插入的PC中显示了 USB 控制器的序列",而不是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天全站免登陆