Previous to this, Raspberry Pi â Installing a RS232 Serial Port delved into installing a RS232 port on the Raspberry Pi. This subsequent article offers alternative interface options as the popular XBit RS232 level-shifter board has been out of stock for a considerable period.
There are two primary RS232 interface options you can choose from for serial connectivity:
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:
- PL2303HX USB to TTL to UART RS232 COM Cable module Converter
- MAX232 RS232 to TTL Converter Adapter Board
- 40pcs Female to Female 2.54mm 0.1 in Jumper Wires F/F
- Jumper Wires Premium 6âł F/F Pack of 10
Serial Communication via USB
If your goal is to simply communicate with your Raspberry Pi using its serial UART, a USB interface might be the better choice. Fortunately, many modern computers and laptops now rely on USB ports rather than traditional RS232 DB9 connectors, making a USB connection a practical solution.
The following adapter is only $5.47 USD and it provides a USB to serial converter chip:
This adapter is built around the Prolific PL2303HX chipset. To utilize this USB-to-serial interface, youâll need to install a USB serial port driver on your host operating system. Fortunately, many popular platforms already come with support for Prolific drivers. But in case you need it, the drivers can be found here: Â http://prolificusa.com/portfolio/pl-2303hx-usb-to-serial-bridge-controller/
NOTE: Before connecting the USB adapter to the Raspberry Pi, ensure that the RED lead is securely insulated to prevent it from making contact with any other pins or components. Note that this RED wire carries +5VDC, which could potentially damage the Raspberry Pi if connected incorrectly.
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 projects and applications requiring hardware devices interfacing, a standard RS232 serial device with a DB9 connector is often the preferred choice. Unlike USB-based solutions, a standard serial port like this doesnât require any additional drivers, as RS232 communication is standardized at the hardware level. Moreover, RS232 can support longer distance transmissions, with the maximum distance depending on the 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.
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
Although the official Debian and Raspbian operating system images are provided as disk images, they are preconfigured to properly support the Raspberry Pi console shell over hardware serial. This feature can be really handy when you want to login to your Raspberry Pi and do not have a monitor with you or when you cannot setup network remote access.
To physically communicate with your Raspberry Pi, open a terminal emulator software which can be Hyperterminal, Procom Plus or Indigo Terminal Emulator. Set the parameters of the settings to â115200, N, 8, 1 and establish the connection in the serial port. If necessary, once or twice hit the Enter key to show the promt. After connect, login with the needed credentials to avail directly in the connection made.
Software use of the Serial Port
If you plan to utilize the serial port for a software application running on the Raspberry Pi, a setup adjustment is necessary to prevent the console from occupying this port. By default, the serial port is configured as a console port for interacting with the Linux OS shell. The following instructions will guide you through disabling the port for 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
Proceed by modifying the â/boot/cmdline.txtâ configuration file by removing the existing parameters âconsole=ttyAMA0,115200â and âkgdboc=ttyAMA0,115200â. This step is crucial in disabling the serial portâs default allocation for console access.
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.
To comment a line place pound sign (â#â) in front of the line. Preceded by a pound sign (â#â) in the line, Linux will not pay attention to this configuration line.
Save the â/etc/inittabâ file and then issue this command to reboot the Raspberry Pi:
sudo reboot
Once the configuration changes have taken effect, you can now successfully use the serial port for your software application. Assign the device address âttyAMA0â in your application to access the serial port, ensuring a seamless integration with your Raspberry Pi.
If are interested in using the serial port with Java programming, please see this page:Â http://pi4j.com/example/serial.html
To enhance safety, Iâve revised the wiring diagram and photographs for the USB TTL adapter approach by removing the 5VDC RED pin connection. Although it was technically functional, I deemed it more prudent to eliminate this connection to avoid the risk of current flowing from the USB connection/adapter back into the Raspberry Pi.
Source: Raspberry Pi â RS232 Serial Interface Options (Revisit)