How to Assign a USB port in Raspberry PLC

Rename your devices in the USB ports of the industrial Raspberry Pi PLC controller for a better organization with industrial automation
October 20, 2021 by
How to Assign a USB port in Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez

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.

Your Dynamic Snippet will be displayed here... This message is displayed because you did not provided both a filter and a template to use.

Requirements

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
Command lsusb - How to Assign a USB port in Raspberry PLC

2. Plug the USB.

Plug the USB to the Raspberry PLC - How to Assign a USB port in Raspberry PLC

3. Type again:

lsusb
Type again command lsusb - How to Assign a USB port in Raspberry PLC

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
In order to identify the USB if it is a camera:

In case you are using a USB camera. This will show information like the port that is being used: /dev/video0

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
Find the IDs of your device - How to Assign a USB port in Raspberry PLC

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"
Add the subsystem, idProduct, idVendor and set the name to the symlink attribute - How to Assign a USB port in Raspberry PLC

7. Load the device administrator.

sudo udevadm trigger

 Test the new USB port name

  • ls -l /dev/ttyUSB*
    ls -l /dev/video0
Test the new USB port name - How to Assign a USB port in Raspberry PLC

Test it by unplugging and plugging the camera, and check that now. You will identify it by its name!

​Search in our Blog

How to Assign a USB port in Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez October 20, 2021
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>