USB COM port number assignment

I have several arduinos connected via USB COM ports to a Pi running node-red.
The arduinos send and receive JSON strings to node-red.
The assigned com port numbers are not guaranteed to remain the same on reboot.
I know there are ways to use PID and VID to identiy devices, but this does not help if arduinos are identical, and especially if arduinos are replaced/ swopped out in the field.
The only way i can think of is to use a tag in the JSON strings to “memorise” which arduino is on which port. Am i missing something?

Welcome to the forums @MichaelBreytenbach

I don't do arduino, but is this a true serial connection?
if so - rules state serial-by-id should be using the devices serial number, to represent the serial port.

Example, I use serial-by-id to make sure im connecting to the correct device.
and this make no difference if the "normal" port name (dev/tty*) changes - serial-by-id doesnt

/dev/serial/by-id/usb-0658_0200_E4051402-4A02-010A-1834-041400A6BE70-if00

You can then, match the arduino by its Serial ID

This becomes untrue however, when the devices are a cheap clone, and the manufacturer not creating a unique serial number.

2 Likes

Marcus, that requires updating the unique serial number every time a faulty arduino in the field is replaced.
I guess i am anwering my own question. The only way to keep system tolerent of changes to harware is in the software.
Has anyone out there ever made a flow that “remembers” which serial node belongs to which port?

Surely you only need the serial port ID of the PI that the Arduinos are connecting to?

Unfortunately, with USB, the serial ports are not intrinsically identifiable. The same device may connect as usbTTY0 one time and usbTTY1 the next time.

1 Like

Yup,

It’s why I use serial-by-id.

Providing the manufacturer of the device being connected plays nicely and is reputable, will usually be unique and constant every time.

But you can write udev rules that will add a symlink for a serial device based on which physical port it is connected to.

So as long as you always plug the replacement device into the same socket it will get the right simlink.

1 Like

Yes, but usually that is not required. by-id will do it without messing with rules. Also udev rules do not solve the OP's problem that he wants to be able to swap the Arduino out with a new one in the case of failure, without changing the server.

But it would solve the OPs problem, as long as they plugged the replacement device in the same physical socket.

I've used this to identify really cheap USB Serial adaptors that all had a same id,

Hardillb, i will defintely try your suggestion of using the same physical sockets for each arduino.
I was not aware that the 4 usb sockets on the Pi can be distinguished from one another.
Thanks everyone.

1 Like

Oh yes, I had forgotten that you could identify the socket.
@MichaelBreytenbach this link may be helpful. How To Write Udev Rules | Hackaday
If you plug them both in then, assuming they are /dev/ttyUSB0 and 1 then run
udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)
and the same for ttyUSB1, then you can look for the differences to see what you can use in the rule to identify them.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.