Contributions

Contributions are appreciated and used to host this site. Thank You for your support.

Feature Products
  • Raspberry Pi with Java: Programming the Internet of Things (IoT)
    Raspberry Pi with Java: Programming the Internet of Things (IoT)
  • Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
    Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
  • Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
    Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
  • Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
    Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
  • Getting Started with Raspberry Pi
    Getting Started with Raspberry Pi
  • Raspberry Pi User Guide
    Raspberry Pi User Guide
  • PiBrella LED Add On Board
    PiBrella LED Add On Board
  • Diversitech® WS-1 - Wet Switch Flood Detector
    Diversitech® WS-1 - Wet Switch Flood Detector
  • Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
    Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
  • Floodstop Washing Machine Valve Shutoff Kit
    Floodstop Washing Machine Valve Shutoff Kit
  • Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
    Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
  • Floodstop Individual Water Appliance Additional Water Sensor XS-01
    Floodstop Individual Water Appliance Additional Water Sensor XS-01
  • Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
    Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
  • Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Metra 70-2002 Radio Wiring Harness for Saturn 00-05
    Metra 70-2002 Radio Wiring Harness for Saturn 00-05
  • Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
    Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
Saturday
Oct202012

Raspberry Pi - RS232 Serial Interface Options (Revisit)

In the previous article Raspberry Pi - Installing a RS232 Serial Port we discussed how to install a RS232 port on the Raspberry Pi.  This is a follow up article to suggest a few alternative interface options as the XBit RS232 level-shifter board has been unavailable (sold out) for while now.

There are two primary RS232 interface options you can choose from for serial connectivity:  

  • USB (USB to Serial Adapter)
  • DB9 (Level Shifter)

Once you have a serial interface connected you can use the serial port for

(Click one of the above options to jump to that part of the article.)

 

Shopping List

The following items are included in this article:

 

Serial Communication via USB

If you are just looking to communicate to your Raspberry Pi via its serial UART, then you may prefer a USB interface.  Most recent models of computers and laptops do not have the traditional RS232 DB9 port anymore, so connecting using a USB port may be preferred.   

The following adapter is only $5.47 USD and it provides a USB to serial converter chip:     

This adapter is based on the Prolific PL2303HX chipset.  To use this USB to serial interface you will have to install a USB serial port driver on your host operating system.  Many operating systems already include support for theserolific drivers.  But in case you need it, the drivers can be found here:  http://prolificusa.com/portfolio/pl-2303hx-usb-to-serial-bridge-controller/

Below is a wiring diagram illustrating how to connect the USB to serial interface:

Photos of the connected USB to Serial interface (click to enlarge):

NOTE:  Please secure the RED lead from the USB adapter so that it does not come into contact with any of the other pins or components on the Raspberry Pi.  This RED pin carries +5VDC and could damage the Pi if it makes contact.

Now that you have the serial interface connected, you can skip down to the Serial Console section to test the interface.

 

Serial Communication via DB9 (Level Shifter)

For certain applications and especially project involving interfacing with other hardware devices a standard RS232 serial device with a DB9 connector is preferred.  A standard serial port such as this does not require any drivers.  RS232 serial communication is standardized at the hardware layer.  RS232 communication can also achieve longer distance runs (maximum distance depends on baud rate).  

The following interface adapter is available for $9.99 USD:

In addition to the adapter, you will need at least 4 female to female 2.54mm .1 in jumper wires. 

Here are a couple of purchase options:

Why is special circuitry (level shifter) needed for RS232 serial communication?

So .. what a level shifter  and why is it needed you ask.  A level shifter is a circuit that can take the low voltage (±3.3VDC) TTL signals for serial transmit (TX) and receive (RX) from the UART on the Pi and shift them to ±5VDC the voltage signals required for RS232 standard communication.  Want to know more?  Click here.   

Below is a wiring diagram illustrating how to connect the level shifter serial interface:

Now that you have the serial interface connected, you can skip down to the Serial Console section to test the interface.
(Use a straight-thru cable for connecting to a computer.) 


Serial Console

The Debian/Raspbian distribution images include support out-of-the-box for accessing the shell console via the hardware serial port.  This can be extremely convenient if you need to access your Raspberry Pi when it is not connected to a monitor and network remote access is not available.

Open a terminal emulation software such as Hyperterminal, Procom Plus, or Indigo Terminal Emulator and connect to the serial port using settings "115200, N, 8, 1".   You may need to press the enter key a time or two to see the prompt.  Authenticate using your credentials and you are good to go.         

Here is a screenshot of the terminal displaying the boot up information and then prompting for a login:

 

Software use of the Serial Port

If you intend to use the serial port for a software application running on the Raspberry Pi, there is a bit of configuration required to disable the console from using this port.   By default, the serial port is configured as a console port for interacting with the Linux OS shell.  The following steps will guide you through disabling the port from console access.

First, lets make of backup of the two files that we intend to modify.

sudo cp /boot/cmdline.txt /boot/cmdline.bak
sudo cp /etc/inittab /etc/inittab.bak

Next, we need to remove the "console=ttyAMA0,115200" and "kgdboc=ttyAMA0,115200" configuration parameters from the "/boot/cmdline.txt" configuration file. 

To edit the file use this command:

sudo nano /boot/cmdline.txt

The file probably contains this default configuration line:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 
console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

After removing the two configuration parameters, it will look similar to this:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 
elevator=deadline rootwait

 

The last step is to edit the "/etc/inittab" file and comment out the use of the "ttyAMA0" serial port.  To edit the file use this command:

sudo nano /etc/inittab

Now towards the bottom of the file, look for a configuration line that includes the "ttyAMA0" port address.

Place a pound sign ("#") in front of the line to comment it out.  With a pound sign ("#") at the beginning of the line, Linux will ignore this configuration line.  

Save the "/etc/inittab" file and then issue this command to reboot the Raspberry Pi:

sudo reboot

Now you are ready to use the serial port with a software application and the operating system won't interfere with the port.  Use the device address "ttyAMA0" in your application to access this serial port.  

If are interested in using the serial port with Java programming, please see this page: http://pi4j.com/example/serial.html

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (36)

Correction ... the IR remote is based on the lirc_rpi project here, and uses the GPIO pin, http://aron.ws/projects/lirc_rpi/
So I meant that I don't want to use up system resources in such a way that prevents both the IR decoding and RS-232 based I/O at the same time.

The Raspberry pi is going to pretend to be a dumb printer target device and dump text (that I enhance and massage on the HDMI display, like a Kiosk, so need bullet-proof design that won't drop characters or lock up). This is one of those great experiments where they've been using a PC to do this, which is just nuts.

July 31, 2013 | Unregistered CommenterDavid Lethe

According to http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf (linked to from http://elinux.org/RPi_Hardware#Components ) the Pi's UART has separate 16-byte send and receive FIFOs, so there should be no danger of dropping characters at the same time as decoding IR received from another GPIO pin. With a 700MHz CPU the Pi is quite capable of doing several things at once ;-)

July 31, 2013 | Unregistered CommenterAndrew Scheller

Thank you for the link, Andrew. I did just confirm I only have to care about a 3-wire, XON/XOFF RS232 designed to interface with a DB9 on a PC, so this does mean I don't have to worry about DTR/RTS and all those other signals.

So what RS-232 implementation is rock-solid reliable (hardware AND drivers), and gives me most amount of flexibility with async vs sync and canonical I/O. I'm not using this as a printer or console device so don't want to go down the path of choosing a device that won't let me use standard tried-and-true serial I/O programming as shown in the link below.

http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html#AEN144

July 31, 2013 | Unregistered CommenterDavid Lethe

To make the task of modifying /etc/inittab and /boot/cmdline.txt easier, I've written a little script which can do this for you (and also 'undo' those changes again, should you decide you want to use the serial console in future)
https://github.com/lurch/rpi-serial-console

September 8, 2013 | Unregistered CommenterAndrew Scheller

Very nice illustration. Good Job!

October 2, 2013 | Unregistered CommenterJ Zumwalt

Procedure needs to be updated for Pi3 and Jessie.

November 13, 2016 | Unregistered CommenterJohn

farnshani e3d3fd1842 https://itraplantic.com/glastivanu

December 21, 2021 | Unregistered Commenterfarnshani

farnshani e3d3fd1842 https://itraplantic.com/glastivanu

December 21, 2021 | Unregistered Commenterfarnshani

farnshani e3d3fd1842 https://itraplantic.com/glastivanu

December 21, 2021 | Unregistered Commenterfarnshani
December 21, 2021 | Unregistered Commenterreatcas
December 21, 2021 | Unregistered Commenterreatcas
December 21, 2021 | Unregistered Commenterreatcas
December 21, 2021 | Unregistered Commenterreatcas

cameramm e3d3fd1842 https://siemefo.com/urelalryt

December 21, 2021 | Unregistered Commentercameramm

cameramm e3d3fd1842 https://siemefo.com/urelalryt

December 21, 2021 | Unregistered Commentercameramm

cameramm e3d3fd1842 https://siemefo.com/urelalryt

December 21, 2021 | Unregistered Commentercameramm

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Raspberry Pi - Build a GPIO Testing Board | Main | Raspberry Pi - Installing the Edimax EW-7811Un USB WiFi Adapter (WiFiPi) »