Raspberry Pi to a Serial Port


17 posts
by balajiv » Thu Jun 06, 2013 4:21 pm
I want to read the serial port data on a device using Raspberry Pi. It means connecting the USB Port of Raspberry Pi to the serial port of a device.

Can someone please provide pointers for the same ? I am seeing more queries/ articles related for other way round i.e connecting to the serial port of Raspberry Pi.
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by SteveSpencer » Thu Jun 06, 2013 4:48 pm
You would typically use a USB/Serial converter. There are two basic types. The first one is commonly used by people talking to microcontrollers and similar devices, it has a USB at one end, and a wiring connector (usually 4 or 6 pins or sockets) at the other, and is designed to use TTL level voltages.

The second is a "true" USB/Serial converter and has USB at one end and a DB9 or DB25 (although not often these days!) connector at the other. The voltage levels at that end are RS-232 "standard" and should not be connected directly to anything on the Pi.

Both kinds are freely available from on-line stores such as Amazon, here are UK links for the "true" serial kind...
http://www.amazon.co.uk/ABC-Products%C2 ... USB+serial
... and the TTL level kind...
http://www.amazon.co.uk/USB-Serial-TTL- ... +to+serial

When plugged in, the Pi will see the cable as a serial port, although I'm not entirely sure what name the device would have, except it won't be /dev/ttyAMA0 :)
Using lsusb or dmesg after plugging it in should be enlightening though.
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...
Posts: 122
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK
by klricks » Fri Jun 07, 2013 4:11 am
balajiv wrote:I want to read the serial port data on a device using Raspberry Pi. It means connecting the USB Port of Raspberry Pi to the serial port of a device.

Can someone please provide pointers for the same ? I am seeing more queries/ articles related for other way round i.e connecting to the serial port of Raspberry Pi.


Is your device serial TTL or RS232?
There is no reason you can't use the serial port of the RPi. Either of these will work and your serial device won't know the difference:

1) Connect a 3.3V TTL to RS232 adapter to the serial port (GPIO) on the RPi.
(If your device is serial TTL, then you can connect the devices directly as long as both systems are using 3.3V levels).
Or
2) Connect a USB to serial adapter to a USB port on the RPi.
(If your device is serial TTL then use a USB to TTL serial converter)

I prefer the 1st way as I don't want to tie up a USB port.
This is how I connected to my serial (RS232) weather station.
http://64.13.91.137:86/Comp/RPi/Serial.html
Go here for my RPi writeup. Basic config, Serial Port add-on etc:
http://home.budget.net/~klricks/Comp/RPi/Rpi.html
Posts: 1020
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
by balajiv » Fri Jun 07, 2013 10:26 am
SteveSpencer wrote:You would typically use a USB/Serial converter. There are two basic types. The first one is commonly used by people talking to microcontrollers and similar devices, it has a USB at one end, and a wiring connector (usually 4 or 6 pins or sockets) at the other, and is designed to use TTL level voltages.

The second is a "true" USB/Serial converter and has USB at one end and a DB9 or DB25 (although not often these days!) connector at the other. The voltage levels at that end are RS-232 "standard" and should not be connected directly to anything on the Pi.

Both kinds are freely available from on-line stores such as Amazon, here are UK links for the "true" serial kind...
http://www.amazon.co.uk/ABC-Products%C2 ... USB+serial
... and the TTL level kind...
http://www.amazon.co.uk/USB-Serial-TTL- ... +to+serial

When plugged in, the Pi will see the cable as a serial port, although I'm not entirely sure what name the device would have, except it won't be /dev/ttyAMA0 :)
Using lsusb or dmesg after plugging it in should be enlightening though.


Thanks, Steve. Most likely, I would have to use USB to Serial "true" connector. So, I would have to connect the USB end to RPi and the Serial end to the device, say, a PC. Is it possible ?

If yes, do I need any drivers for the same ?

Once the connection is successful, I need to use lsusb or dmesg.

Please correct me, if my understanding is wrong.
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by SteveSpencer » Fri Jun 07, 2013 11:05 am
balajiv wrote:[Thanks, Steve. Most likely, I would have to use USB to Serial "true" connector. So, I would have to connect the USB end to RPi and the Serial end to the device, say, a PC. Is it possible ?

If yes, do I need any drivers for the same ?

Once the connection is successful, I need to use lsusb or dmesg.

Please correct me, if my understanding is wrong.


If you are connecting to a PC with a serial port, yes. However, most USB-Serial cables with DB9 connectors are wired the same way as the port on a PC, so you will also need a null-modem cable which allows you to connect the two together. This is a female-female cable with the Tx/Rx signals switched from one end to the other so Tx at one end goes to Rx at the other and vice versa.
For the Pi, you shouldn't need any drivers, as they are auto-detected.

If you issue an lsusb command, it will list the USB devices connected, and confirm that the device is recognised.
Using dmesg will let you see the kernel messages, and will probably include the connection of the USB device, and should tell you the device name, which will be /dev/SOMETHING

Steve
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...
Posts: 122
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK
by balajiv » Fri Jun 07, 2013 1:00 pm
SteveSpencer wrote:
balajiv wrote:[Thanks, Steve. Most likely, I would have to use USB to Serial "true" connector. So, I would have to connect the USB end to RPi and the Serial end to the device, say, a PC. Is it possible ?

If yes, do I need any drivers for the same ?

Once the connection is successful, I need to use lsusb or dmesg.

Please correct me, if my understanding is wrong.


If you are connecting to a PC with a serial port, yes. However, most USB-Serial cables with DB9 connectors are wired the same way as the port on a PC, so you will also need a null-modem cable which allows you to connect the two together. This is a female-female cable with the Tx/Rx signals switched from one end to the other so Tx at one end goes to Rx at the other and vice versa.
For the Pi, you shouldn't need any drivers, as they are auto-detected.

If you issue an lsusb command, it will list the USB devices connected, and confirm that the device is recognised.
Using dmesg will let you see the kernel messages, and will probably include the connection of the USB device, and should tell you the device name, which will be /dev/SOMETHING

Steve


Thanks a lot, Steve. Will try and let you know the result. :-)
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by FTrevorGowen » Fri Jun 07, 2013 2:33 pm
FWIW here is an example of a USB-Serial device connecting a Pi to an old RS232 printer/terminal (back in Nov. 2012): http://www.cpmspectrepi.webspace.virgin ... apter.html
Trev.
Mainly running "Wheezy Raspbian" on four Pi's (an A, B1 & 2xB2). Notes about them begin at http://www.cpmspectrepi.webspace.virginmedia.com/raspberry_pi/raspiidx.htm
User avatar
Moderator
Moderator
Posts: 1469
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
by balajiv » Mon Jun 10, 2013 1:26 pm
I connected the USB end of true USB to serial connector cable to Raspberry Pi; used a gender changer cable to connect the other serial end of the cable to the CPU of PC.

Turned on the CPU as well as the Raspberry Pi.

On giving the lsusb command, I see the result as:

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 005: ID 413c:2003 Dell Computer Corp. Keyboard

On using the dmesg command:

pi@raspberrypi ~ $ dmesg | grep tty
[ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1360 bcm2708_fb.fbheight=768 bcm2708.boardrev=0xe bcm2708.serial=0xdfe8d5ba smsc95xx.macaddr=B8:27:EB:E8:D5:BA sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[ 0.000000] console [tty1] enabled
[ 0.584216] dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3
[ 0.908140] console [ttyAMA0] enabled
[31328.703340] usb 1-1.2: pl2303 converter now attached to ttyUSB0

Can you please let me know it is fine ? If not, what is the issue ?

Thanks.
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by SteveSpencer » Mon Jun 10, 2013 1:53 pm
Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port


[31328.703340] usb 1-1.2: pl2303 converter now attached to ttyUSB0


Looks fine :)

Your new "serial port" on the Pi is /dev/ttyUSB0, from the look of that. Now, whether or not you have your cabling correct between the USB serial end and the other device is not something this will tell you.

What software are you planning to use on the Pi to send/receive data on the new serial port?

Steve
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...
Posts: 122
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK
by balajiv » Mon Jun 10, 2013 2:02 pm
Steve,

I am planning to use minicom. Is it fine ?

Also I was expecting something like ttyS* as the serial port device. Is it not the right expectation ? :-(
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by balajiv » Mon Jun 10, 2013 2:59 pm
I am reading like the output of dmesg command must be like:

$ dmesg | grep tty

Output:

[ 37.531286] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 37.531841] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 37.532138] 0000:04:00.3: ttyS1 at I/O 0x1020 (irq = 18) is a 16550A
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by Excal » Mon Jun 10, 2013 3:51 pm
I have bad experiences with usb to serial.

I ordered http://www.ebay.com/itm/New-MAX3232-RS232-Serial-Port-To-TTL-Converter-Module-DB9-Connector-3-3-5V-Input-/170883124088?pt=LH_DefaultDomain_0&hash=item27c96d8b78 for 2 euro, still in shipping though, ill let you know the results.
Last edited by Excal on Tue Jun 11, 2013 10:15 am, edited 1 time in total.
Posts: 3
Joined: Mon Jun 10, 2013 3:43 pm
by SteveSpencer » Mon Jun 10, 2013 3:54 pm
Minicom should be fine for a terminal emulation program.

On the Pi, your serial port (from the USB/Serial) is /dev/ttyUSB0. The output you just quoted has, I guess, come from a different machine, which is equipped with what appear to be two genuine UART chips (16550A chips, to be exact), and they result in ports with different names on that machine.

At some point in the Debian software, someone decided that /dev/ttyS??? would be good names for "proper" serial ports, and /dev/ttyUSB??? would be good names for serial ports which were USB/Serial converters.

Steve
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...
Posts: 122
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK
by balajiv » Wed Jun 12, 2013 12:49 pm
I tried screen program. It seems to be helpful.

Can there be something better ?
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by jujubee » Thu Jun 13, 2013 7:39 pm
Hey guys,

I am also using a usb to serial adapter on the Raspberry Pi and I am having some issues. The Raspberry Pi (usb end) is connected to a Roomba/iRobot Create (serial end). I have used screen and minicom and I cannot send commands to the roomba, even though I can see there is a connection ....and when I power on the Roomba it sends data to the screen. I have tried messing with the set up in minicom and played with the various settings and no luck. I am receiving data form the Roomba but I cannot get the Pi to send data to it. Any help or advice would be appreciated. Thanks!
Posts: 1
Joined: Wed Jun 12, 2013 6:17 pm
by balajiv » Tue Jun 18, 2013 4:46 pm
Thanks everyone for the guidance.

I was able to connect the RPi to another device through serial to USB converter. I am able to connect to the device using the command:

screen /dev/ttyUSB0 115200

On giving the command, I reach a blank screen; on typing enter, I get CFE prompt which has help commands.

When I try the same with another device, I am not getting any prompt; at the same time I am seeing some junk character; what could be the issue here ?

Thanks in advance
Posts: 33
Joined: Mon May 06, 2013 6:08 am
by hubie » Wed Jun 26, 2013 7:26 pm
Typically seeing junk characters when doing serial port comm means you are using the wrong baud rate.

Instead of 115200, try 9600 or 4800. Those two are very commonly used. If those don't work, you can work down in speed: 57600, 38400, 28800, and 19200. If none of those work, then it could be a bit/parity setup issue. Almost everything these days uses 8-bits and no parity, so I doubt that will be an issue.
Posts: 1
Joined: Wed Jun 26, 2013 6:56 pm