I really like my Psion. Nice keyboard, black and white, works great in sunlight. Runs for forever off a few double AA batteries. I also really like The Raspberry Pi Zero. A little full-fat Linux machine, smaller than a credit card that can run quite happily on battery power. I want to make these two devices talk so I’ve got a little lightweight portable Linux terminal.

Psion 5MX Full Hero

Raspberry Pis have always had onboard serial support. Serial support allows you to connect two lines between your Pi and a compatible device, and then read and write to that serial port. We can enable the Pi’s console to communicate over serial and use serial to directly interface with our Pi’s console. The Pi’s serial operates at the voltage level of the Pi 3.3V - the most common method of interfacing with Pi serial is using a UART adapter like the one below, this plugs in to a host computer and allows communication with TTL UART devices.

Typically, legacy serial devices conform to RS232, a standard for voltages, ports, and protocols. Our Psion conforms to RS232, which is higher than the acceptable voltage range for our Pi. An RS232-TTL converter sits in the middle of the two devices and translates the voltages. The one below is based on the max3232 chip and provides 4 lines, 2 in each direction. The directionality of the channels is important, it will only allows traffic in the expected direction.

Setting up the Pi - UART

Raspberry Pis with onboard Bluetooth have two serial ports - full UART (ttyAMA0) and mini UART (ttyS0). The full UART is reserved for Bluetooth. The mini UART works, but the full UART works at higher speeds and also supports hardware flow control.

Switching to the full UART requires either disabling the bluetooth, or telling the bluetooth to use the mini UART. We can do this with overlays. Edit /boot/config.txt and add the following lines:

# Disable Bluetooth - switch UART
dtoverlay=pi3-disable-bt

We also need to instruct our Pi to use the serial terminal with the console. Add the following line to the same file:

enable_uart=1

We can now wire our Pi to our RS232 adapter. Using jumper wires, connect pin 8/GPIO 14 on the Pi to TX on the adapter, Pin 10/GPIO 10 to RX, pin 6/GND to GND and pin 1/3.3V to VCC.
Since the Psion RS232 cable is also null modem, we a null modem adapter and a gender changer on the Psion/RS232 side.

Raspberry Pi / RS232 TTL Overview

I’m using the Hermes terminal program (link via Wayback machine). Set up your serial client for 115200 baud, 8N1, with no hardware flow control. If it’s all gone well so far, press return on your Pi, and see if you get a response.
You’re in the console terminal, from a fresh boot you’re probably should be at the login prompt. Login, and welcome to your serial Pi.

Psion 5 Serial Login

From here you’ve now got a basic working serial terminal to a fully functional Raspberry Pi. Why not send a tweet using rainbowstream, the terminal based twitter client?

Overflow

Our terminal does have a flaw. If you go in to a large directory and enter ls, you’ll probably find you get some serial overflow problems. For a truly stable experience, we’re going to need to enable hardware flow control.

Psion 5 Serial Overflow

RTS/CTS is a simple mechanism that uses high/low signals to notify when data is going to be transmitted and when it is safe to do so. If the client needs more time to process what it already has, it can raise a block to tell the sender to wait before sending more data.

Setting up hardware flow control

The Raspberry Pi can support RTS/CTS on the full UART, but it requires a little bit of additional setup.

First, we need to switch the mode on two additional pins. The tool rpirtscts will allow you to switch the two pins from GPIO to RTS/CTS.

sudo apt install build-essential git
git clone https://github.com/mholling/rpirtscts 
cd rpirtscts
make
sudo ./rpirtscts on

You’re then going to need to enable another overlay. This one does not come with the Raspian install, but we can source it from the AtariSIO project. The AtariSIO project contains a collection of overlays that are designed for enabling serial and RTS/CTS for use with Atari floppy drives. Turns out they work great for our use.

We need to grab the file, then move it in to the appropriate location:

wget https://github.com/HiassofT/AtariSIO/blob/master/contrib/rpi/uart-ctsrts.dtbo?raw=true -O uart-ctsrts.dtbo
mv uart-ctsrts.dtbo /boot/overlays/

We then enable the overlay, in the same way we did for the other overlays in /boot/config.txt:

# Disable Bluetooth - switch UART, enable CTS/RTS
dtoverlay=pi3-disable-bt
dtoverlay=uart-ctsrts

Finally, on boot we need to tell the serial driver to use RTS/CTS. I’ve tried a few approaches, but so far the most reliable has been adding the following to the bottom of ~/.bashrc. This will tell the serial driver to use CTS/RTS on login.

stty -F /dev/ttyAMA0 crtscts  

We now need two additional wires, one from pin 36/GPIO 16 for CTS, and one from pin 11 GPIO 17 for RTS. These map to their respective ports on the RS232/TTL adapter. Mine now looks like this:

Pi / RS232 TTL with RTS/CTS

When we now list our long directory, we no longer get serial overrun errors and our contents is listed correctly.

Psion 5 Serial No Overflow

We can also try a more taxing demo. CMatrix is quite popular for this, and here it is running with no overflow problems:

Psion 5 Cmatrix Demo

What’s Next?

Portability - I was testing this rig at Electromagnetic Field using a battery pack and it wasn’t bad, but it could be better. I’m designing a HAT with my a RS232-TTL converter, a switched null modem converter and a JST with DC-DC for a lipo battery pack. I’m aiming for a small portable Pi that can serve as an adjunct to my Psion. I’m hoping to have the first version of that ready in the next few weeks.

I also have a small encoding problem - for some reason, £ signs are being translated as # signs. I assume it’s something in the locale, but it’s a small blocker. All suggestions are welcome.

References

As well as any links already in the post, putting this together has required a lot of additional sources, which require credit: