Devices switching TTYUSB on raspberry PI

Hi I’m new to Raspberry pi and trying to get 2 devices to assign to exact TTYUSB
Below is some info that may help. Any help is appreciated.

Thanks
Chris Hopper


lsusb

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 001 Device 043: ID 1a86:7523 QinHeng Electronics CH340 serial converter

Bus 001 Device 042: ID 1546:01a9 U-Blox AG u-blox GNSS receiver

Bus 001 Device 041: ID 0424:2512 Microchip Technology, Inc. (formerly SMSC) USB 2.0 Hub

Bus 001 Device 044: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)

Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

____________________________________________________________________________________________________________-
#########FAULT###################
dmesg | grep ttyUSB #plug in gps first

[6687.172588] usb 1-1.2.2: ch341-uart converter now attached to ttyUSB0

[ 6690.337939] usb 1-1.1: FTDI USB Serial Device converter now attached to ttyUSB1

dmesg | grep ttyUSB #plug in gps second

[ 6781.750850] usb 1-1.1: FTDI USB Serial Device converter now attached to ttyUSB0

[ 6788.089243] usb 1-1.2.2: ch341-uart converter now attached to ttyUSB1


#python script ping assigned to ttyusb1

def read_ping_data(data_list, pole_height, script_running):

myPing = Ping1D()

myPing.connect_serial(“/dev/ttyUSB1”, 115200)

myPing.set_speed_of_sound(1500) # Hardcoded speed of sound, consider using a variable

sudo nano /etc/udev/rules.d/99-usb-serial.rules

Rule for u-blox GNSS receiver to always use ttyUSB0

SUBSYSTEM==“tty”, ATTRS{idVendor}==“1546”, ATTRS{idProduct}==“01a9”, SYMLINK+=“ttyUSB0”

Rule for other devices to use ttyUSB1

SUBSYSTEM==“tty”, ATTRS{idVendor}==“0424”, ATTRS{idProduct}==“2512”, SYMLINK+=“ttyUSB1”

SUBSYSTEM==“tty”, ATTRS{idVendor}==“0403”, ATTRS{idProduct}==“6015”, SYMLINK+=“ttyUSB1”

<O

<E

sudo udevadm control --reload-rules

sudo udevadm trigger


still switching


I even tried to change this to ttyUSB2
SUBSYSTEM==“tty”, ATTRS{idVendor}==“0403”, ATTRS{idProduct}==“6015”, SYMLINK+=“ttyUSB1”

2 Likes

Hey Chris,

From your post it seems like the devices you are using for this are a CH340 serial converter and a FTDI USB Serial Device converter. If I have got this wrong please let me know.

Are you sure your vendor ID and product ID for your devices are correct when you set up your rules?

The UDEV rules must correspond to the correct vendor IDs and product IDs if you want them to match a particular device.

The Vendor ID and Product ID are provided by lsusb command.

From the data you provided, these are:

  • CH340 serial converter: ID 1a86:7523 (idVendor:idProduct)

  • FTDI USB: ID 0403:6015 (idVendor:idProduct)

You should setup your rules something like this based on the exact results you get from the lsusb command:

# Set to always use ttyUSB0
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB0"
# Set to always use ttyUSB1
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", SYMLINK+="ttyUSB1"

You will need to reload the udev rules with the following commands for this to take affect:

sudo udevadm control 

Then

sudo udevadm trigger

Hopefully this will help you make some progress with this.

Best of luck!
Sam

1 Like

Bus 001 Device 042: ID 1546:01a9 U-Blox AG u-blox GNSS receiver
which should be
[ 6788.089243] usb 1-1.2.2: ch341-uart converter now attached to ttyUSB1

Is there a way just to give the ping a rule like ttyusb0 for soe reason my python script doesnt require a serial contnect for the gps.

I also tried this but it leads me down a rabbit hole of errors

Im thinking of giving the ping ttyusb0 as it will allows be plugged into the PI.
I take the sparkfun facet off to do other surveying sometimes
sorry if this doesnt make sense

------tried this and did not work-------
sudo nano /etc/udev/rules.d/99-com.rules

SUBSYSTEM==“tty”, ATTRS{idVendor}==“0403”, ATTRS{idProduct}==“6015”, ATTRS{serial}==“DP05Y5V8”, SYMLINK+=“pingusb”, MODE=“0666”

sudo udevadm control --reload-rules

sudo udevadm trigger

#comes up on $ ls /dev/

Error reading Ping data: Failed to open the given serial port: [Errno 16] could not open port /dev/pingusb: [Errno 16] Device or resource busy: ‘/dev/pingusb’

Opening /dev/pingusb at 115200 bps

------Also tried in sudo nano /etc/udev/rules.d/99-serial.rules but doesnt show up on ls /dev/-----

Hi @christopher187811 - I think I have found the approach you’re using. This Raspberry Pi forum post looks promising, but within it is linked this great-looking recipe: Howto: Persistent device names on Raspberry Pi.

which appears to be what you’ve tried. I note there are a few differences.
One thing to sanity check, are your files formatted correctly with correct syntax? These files have to be character-for-character correct or they may just be broken.

It would help if you edit your original posts to use codeblocks, so we can see if everything is exactly as it should be.