RogerInHawaii
Posts: 34
Joined: Wed Jul 31, 2013 11:08 pm

Serial port via USB port

Wed Jul 31, 2013 11:23 pm

I have a device that plugs into a USB port and provides a serial port. It's actually an RF device that acts like a serial port but transmits and receives the data over an RF link.

I've been successful using this device from a PC and controlled by an MFC C++ program. When I do that I reference the serial port using "COM0" (or COM5 or whatever COM port/USB plug the device is plugged into). And it works quite well. I can send and receive data via the "serial port" RF communications.

But now I'm trying to use this device on the Raspberry Pi, without success. I've installed the pySerial library and import it into my program. I use the serial.Serial() method to instantiate a serial port, passing in the "name" of the serial port. I came across one article that indicated I might have to use "/dev/ttyAMA0" as the port name. But that doesn't appear to work. It does indeed successfully instantiate the serial.Serial() object, but it doesn't appear to be communicating with the actual device I have plugged into USB 0. In fact, even when I DON'T have my device plugged in, the serial.Serial("/dev/ttyAMA0") method call succeeds. It appears as though there's some built in serial port on the Raspberry Pi.

HOW do I get access to my USB/Serial device? Do I use serial.Serial() method? What name do I use to reference the appropriate USB port?

User avatar
rpdom
Posts: 11787
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Serial port via USB port

Thu Aug 01, 2013 4:11 am

serial.serial() should work.

The device name will be something like /dev/ttyUSB0

DrMag
Posts: 62
Joined: Sat Jun 01, 2013 7:59 pm

Re: Serial port via USB port

Thu Aug 01, 2013 7:22 pm

When you plug in your RF module, use dmesg to see what device attachment it received... it'll be /dev/ttySOMETHING most likely. Then just pass that as your name.

abqlewis
Posts: 18
Joined: Tue Sep 13, 2011 3:45 pm

Re: Serial port via USB port

Thu Aug 01, 2013 8:00 pm

I tend to be very brute force with stuff like this. I do a "ls /dev/tty*", with the device unplugged. Then plug the device in and repeat the ls command. The difference in the two lists should be your device, and usually shows up as ttyUSB0 or ttyACM0 (or in your case, may be a ttyAMA0). BTW, If you already had a serial device connected, it may be named something like ttyAMA0, so your new device would then be called ttyAMA1.

You can also do a "ls /dev/serial/by-*" and look for a reference to the device you are using. If this works, you could add this to your python script to parse the output and auto find the correct serial port.

RogerInHawaii
Posts: 34
Joined: Wed Jul 31, 2013 11:08 pm

Re: Serial port via USB port

Thu Aug 01, 2013 9:40 pm

Thank you for the info.

As it turns out it's referenced by "/dev/ttyUSB0".

lupandua
Posts: 1
Joined: Tue Nov 14, 2017 4:11 pm

Re: Serial port via USB port

Tue Nov 14, 2017 4:27 pm

Good day Guys

I have a similar problem and need assistance. I am using a Raspberry pi 3 model B to connect a device via a USB port. the device has a serial to USB cable that i connect to the USB ports on the Raspberry. If i connect to my windows laptop, my device connects on COM 3 port when i connect to the PC but when i connect on the raspberry the application fails to connect to any com ports. i have configured the serial port ttyS0 to ttyUSB0 as iam using a USB port.

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

Re: Serial port via USB port

Mon Nov 20, 2017 12:56 pm

lupandua wrote:i have configured the serial port ttyS0 to ttyUSB0 as iam using a USB port.
How are you doing this?
Plug in your Serial to USB device to the Pi and report the output of:

Code: Select all

lsusb
Dave.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 21 guests