Setting up RS-232 on a Raspberry Pi

Anthony Sorace
a.9srv.net
Strand 1 Technologies

ABSTRACT

NOTE: Maybe they only work in the abstract?

The Raspberry Pi can be configured to treat two of its GPIO pins as a uart. This provides a ttl uart, which is much less common than RS-232 on peripheral devices of for talking between systems. An inexpensive converter can give a Raspberry Pi a RS-232 serial port.

Introduction

To convert between TTL and RS-232 signaling, an adaptor is needed. I used a module from DaFuRui¹ which is based upon the very popular MAX3232 chip. The build quality on the module seems good and it is at least relatively tolerant of electrical errors (see below). Assuming your Raspberry Pi already has the GPIO headers in place, you'll only need for F/F jumper wires to connect the module. If the GPIO header is not present, you can add the 40-pin header or directly wire the connection to only the relevant pins (see below).

This works on any (non-pico) model Raspberry Pi.

NOTE: ¹ https://www.amazon.com/gp/product/B07Z5Y1WKX/

Configuring the hardware

The DaFuRui module exposes pins for VCC, RXD, TXD, and GND. These should be wired to the Raspberry Pi's GPIO pins 1, 10, 8, and 6.² When I first wired up the module, I connected VCC to the raspberry pi's pin 4. This will power the module, but at 5V instead of the rated 3.3v. It did not seem to do any damage for the few minutes I had it connected this way, but the unit did get very warm very quickly. I did not test data transmission under this configuration.

NOTE: ² Other options exist for connecting VCC and GND if those pins are unavailable, such as being used by another device; see https://pinout.xyz.

Configuring the software

First we will need to tell the Raspberry Pi bootloader to enable the uart by editing config.txt on the boot volume. If you're doing this on the pi running Plan 9, run c: to mount the boot dos partition, then edit /n/c/config.txt to add this line:

enable_uart=1
Reboot the pi. You should be able to read /dev/eia0status to get the current state of the uart, and set the baud rate³ on the device using something like:
echo b9600 > /dev/eia0ctl
See uart(7) for details.

Testing the results

The simplest test is to run con /dev/eia0 with the converter connected to a suitable serial port on another device.