waynetom
Posts: 1
Joined: Thu Jan 05, 2017 12:24 am

/dev/ttyUSB0 Serial Port Not working

Thu Jan 05, 2017 12:53 am

Hi
Platform Used: Rasp Pi 2 Model B v1.1
OS Release : Raspbian GNU/Linux 8.0 (jessie)

I have a Node-red instance running with two serial ports, one serial in node and one serial out node.
The ports are configured correctly to use /dev/ttyUSB0 and have the green "connected" indicator on.

I have an xbee connected to the USB Adaptor and the serial out node can send messages successfully to my remote xbee.
However I can't get my serial in node to receive messages, I can confirm the messages are being sent successfully, but they do not appear in the debug console of of node red.

I have read a large number of blogs and forums and have edited my /dev/cmdline.txt. to remove all references to /dev/ttyAMA0.

It currently reads ;

dwc_otg.lpm_enable=0 console=tty1, 9600 root=/dev/mmcblk0p7 rootfstype=ext4 rootwait

I have seen references to other files to edit like /etc/initab but I can't find these and think they are not relevant for my OS version.

I have tried to disable the getty service using this command -> sudo systemctl disable [email protected]

However this seemed to have no affect. I am at a loss as to what is actually required.

Can you please help ?

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: /dev/ttyUSB0 Serial Port Not working

Thu Jan 05, 2017 3:44 pm

waynetom wrote:I have read a large number of blogs and forums and have edited my /dev/cmdline.txt. to remove all references to /dev/ttyAMA0.
Unfortunately, none of these blogs or posts have anything to do with your problem! They are (mainly) to do with getting the Pi 3B's Serial Port to work.

'/dev/ttyAMA0' is the UART device which is normally connected to GPIO physical pins 8 & 10, the Pi's serial port pins, on models previous to the Pi 3B.
'/dev/ttyS0' is the UART device which is normally connected to GPIO physical pins 8 & 10 on a Pi 3B.

You are trying to connect using '/dev/ttyUSB0', a USB to Serial Port Converter, with the USB end connected to the Pi. As the '/dev/USB0' device is 100% independent from the '/dev/ttyAMA0' device, the changes you have made to '/boot/cmdline.txt' and the systemctl command have no effect on '/dev/ttyUSB0', but should not do any harm.
waynetom wrote:I have a Node-red instance running with two serial ports, one serial in node and one serial out node.
The ports are configured correctly to use /dev/ttyUSB0 and have the green "connected" indicator on.
I have never used Node-red, and so know nothing about it, but normally '/dev/ttyUSB0' would be a single serial port. You say that you are using two serial ports, are you sure that you are configuring Node-red correctly?

As far as I know, you cannot share serial ports simultaneously among applications. If you want more than 1 application to have access to the serial port, then each one must open the port, exchange it's data, and closed the port again. If one application has opened the port, then no other application will be able to access the port until that application has closed it.

Dave.

wilbe
Posts: 4
Joined: Thu Jun 29, 2017 1:10 pm

Re: /dev/ttyUSB0 Serial Port Not working

Thu Jun 29, 2017 1:20 pm

I have a similar problem.
I want to use two different serial devices on my raspberry, one connected to the GPIO pins and communicates via /dev/ttyS0 without any issues and the other to a USB as a serial device.
Currently everything work via the GPIO pins as the GPS sends the strings through to my Xojo application.
As soon as I plug the GPS into a TTL to USB converter and plug the USB end into the Raspberry then the app does not see the USB when changing /dev/ttyS0 to /dev/ttyUSB0.
The GPS works and the data is displayed with DGPS in the command line with cgps -s, so there is nothing wrong with the data stream or the reference to USB0 as the python code picks up that it is no longer connected to the GPIO but rather connected to the USB. Not quite sure where to start looking for the issue, it might be with Xojo or with the Raspberry.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: /dev/ttyUSB0 Serial Port Not working

Thu Jun 29, 2017 2:58 pm

It's possible that SystemD is setting up a Linux Console on your Serial to USB Converter when you plug it into your Pi, and this prevents other applications like your Python program from talking to the port.

With your USB Converter plugged into your Pi, try running:

Code: Select all

sudo systemctl status [email protected]*
If this returns something like:

Code: Select all

[email protected] - Serial Getty on ttyUSB0
   Loaded: loaded (/etc/systemd/system/[email protected]; disabled)
   Active: active (running) since Thu 2017-06-29 15:41:52 IST; 8s ago
     Docs: man:agetty(8)
           man:systemd-getty-generator(8)
           http://0pointer.de/blog/projects/serial-console.html
 Main PID: 8087 (agetty)
   CGroup: /system.slice/system-serial\x2dgetty.slice/[email protected]
           └─8087 /sbin/agetty ttyUSB0 9600 vt320

Jun 29 15:41:52 RaspberryThree systemd[1]: Started Serial Getty on ttyUSB0.
then SystemD has started a Linux Console on your Serial to USB Converter.

In this case, try running:

Code: Select all

sudo systemctl stop [email protected]*
and try your Python program again.

If "sudo systemctl status [email protected]*" returns nothing, disregard the above.

Hope this helps,
Dave.

wilbe
Posts: 4
Joined: Thu Jun 29, 2017 1:10 pm

Re: /dev/ttyUSB0 Serial Port Not working

Fri Jun 30, 2017 7:28 am

Dave, unfortunately I didn't get a return.

I listed the USB devices so that you can see it does detect the CP210 USB converter.

Code: Select all

[email protected]:~ $ sudo systemctl status [email protected]*
[email protected]:~ $ lsusb
Bus 001 Device 004: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I also stopped the GPSD Deamon from starting up after a reboot, but that also didn't work. I will try a whole new install on the Raspberry maybe I have scratched where I shouldn't have previously.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: /dev/ttyUSB0 Serial Port Not working

Fri Jun 30, 2017 10:36 am

While your Pi is up and running, disconnect your Serial to USB Converter, wait 10 seconds or so, and reconnect it again. Give it another 10 - 20 seconds, then run:

Code: Select all

tail -20 /var/log/syslog
You should see something like:

Code: Select all

Jun 30 11:28:08 RaspberryThree kernel: [243857.673330] usb 1-1.3: new full-speed USB device number 8 using dwc_otg
Jun 30 11:28:08 RaspberryThree kernel: [243857.805518] usb 1-1.3: New USB device found, idVendor=067b, idProduct=2303
Jun 30 11:28:08 RaspberryThree kernel: [243857.805531] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jun 30 11:28:08 RaspberryThree kernel: [243857.805540] usb 1-1.3: Product: USB-Serial Controller D
Jun 30 11:28:08 RaspberryThree kernel: [243857.805548] usb 1-1.3: Manufacturer: Prolific Technology Inc.
Jun 30 11:28:08 RaspberryThree kernel: [243857.806625] pl2303 1-1.3:1.0: pl2303 converter detected
Jun 30 11:28:08 RaspberryThree kernel: [243857.810670] usb 1-1.3: pl2303 converter now attached to ttyUSB0
In my case, I'm using a PL2303 Serial to USB Converter, and you can see on the last line that it's attached to 'ttyUSB0'. What does yours say?

Dave.

wilbe
Posts: 4
Joined: Thu Jun 29, 2017 1:10 pm

Re: /dev/ttyUSB0 Serial Port Not working

Fri Jun 30, 2017 11:57 am

Dave,

I reloaded Raspbian and tried my app again but with no success.
The USB device is connected to ttyUSB0

Code: Select all

Jun 21 10:55:36 raspberrypi kernel: [ 2336.653750] usb 1-1.5: USB disconnect, device number 7
Jun 21 10:55:36 raspberrypi kernel: [ 2336.654378] cp210x ttyUSB0: cp210x converter now disconnected from ttyUSB0
Jun 21 10:55:36 raspberrypi kernel: [ 2336.654446] cp210x 1-1.5:1.0: device disconnected
Jun 21 10:55:36 raspberrypi rsyslogd-2007: action 'action 17' suspended, next retry is Wed Jun 21 10:56:36 2017 [try http://www.rsyslog.com/e/2007 ]
Jun 21 10:55:48 raspberrypi kernel: [ 2348.975892] usb 1-1.5: new full-speed USB device number 8 using dwc_otg
Jun 21 10:55:49 raspberrypi kernel: [ 2349.156178] usb 1-1.5: New USB device found, idVendor=10c4, idProduct=ea60
Jun 21 10:55:49 raspberrypi kernel: [ 2349.156194] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 21 10:55:49 raspberrypi kernel: [ 2349.156203] usb 1-1.5: Product: CP2102 USB to UART Bridge Controller
Jun 21 10:55:49 raspberrypi kernel: [ 2349.156211] usb 1-1.5: Manufacturer: Silicon Labs
Jun 21 10:55:49 raspberrypi kernel: [ 2349.156219] usb 1-1.5: SerialNumber: 0001
Jun 21 10:55:49 raspberrypi kernel: [ 2349.169213] cp210x 1-1.5:1.0: cp210x converter detected
Jun 21 10:55:49 raspberrypi kernel: [ 2349.176164] usb 1-1.5: cp210x converter now attached to ttyUSB0
Jun 21 10:55:49 raspberrypi systemd-udevd[1663]: failed to execute '/lib/udev/mtp-probe' 'mtp-probe /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5 1 8': No such file or directory

wilbe
Posts: 4
Joined: Thu Jun 29, 2017 1:10 pm

Re: /dev/ttyUSB0 Serial Port Not working

Thu Jul 06, 2017 7:00 am

After contacting Xojo, my code was at fault in my app, somehow the port was not being opened when the app starts up.
In order to test if the port works just type cat /dev/ttyUSBn in the console. "n" being the USB number associated with the device. If it returns the strings then you are good to go. :ugeek: I am new to linux and console shortcuts so excuse me.
cat /dev/ttyS0 will return the strings if the GPIO is utilised for serial communication.

Return to “Troubleshooting”