Introduction
Many times, we plug several devices into the USB ports of the industrial Raspberry PLC, and it is difficult to identify which one is the one that we want to use since the names are something like this: /dev/ttyUSB0, dev/ttyUSB1, or /dev/video0, /dev/video1...
For that reason, we will take the ID of each device we want to identify, and assign it to a specific name. This way, whenever you connect the Raspberry Pi industrial PLC to the USB port, you see the given name.
Requirements
- Raspberry PLC >
- Power supply >
- Any device to connect through a USB port. In our case: a USB camera.
Identify the USB port
In order to assign a name for every device, it is better if you first do it step by step, and only connect one device to the USB ports, in order to identify it without any problem.
1. Run the following command and list the USB devices:
lsusb
2. Plug the USB.
3. Type again:
lsusb
And check that the open source PLC Raspberry Pi identifies your USB device.
4. In order to identify the USB port, you can run:
dmesg | grep ttyUSB
5. Find the IDs of your device
udevadm info --name=YOUR-PORT-HERE --attribute-walk
In our case:
udevadm info --name=/dev/video0 --attribute-walk
6. Create a new file with the USB port name rules. Run:
sudo nano /etc/udev/rules.d/10-usb-serial.rules
Add the subsystem, idProduct, idVendor and set the name to the symlink attribute like:
SUBSYSTEM=="usb", ATTRS{idProduct}=="62c0", ATTRS{idVendor}=="0c45", SYMLINK+="WebCam"
7. Load the device administrator.
sudo udevadm trigger
Test the new USB port name
ls -l /dev/ttyUSB*
ls -l /dev/video0
Test it by unplugging and plugging the camera, and check that now. You will identify it by its name!
How to Assign a USB port in Raspberry PLC