Raspberry Pi – RS232 Serial Interface Options (Revisit)

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:

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

Raspberry Pi - RS232 Serial Interface Options (Revisit)

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 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.)

Raspberry Pi - RS232 Serial Interface Options (Revisit) Schematic

Serial Console

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.

SOFTWARE USE OF THE SERIAL PORT

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

Source: Raspberry Pi – RS232 Serial Interface Options (Revisit)


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top