Using the Serial Port

RPi900 connects the DNT900 radio to your Raspberry Pi using the ttyAMA0 serial port. Some familiarity with the use of TTY ports under Linux will be beneficial. Once your serial port and radio are properly configured, communicating with the radio is as simple as writing to and reading from a TTY device.

In these tutorials, Arch Linux ARM is the preferred distribution to use. It’s well-suited to running as a headless server (a likely arrangement when operating your RPi900 as a base or remote station).

Permissions

It is convenient to give yourself the correct permissions to access /dev/ttyAMA0 serial device. Do so by adding yourself to the uucp group:

$sudo usermod -a -G uucp matthew

On the next login, you should now be able to work with /dev/ttyAMA0 without root privileges:

$groups matthew
users uucp
$ls -l /dev/ttyAMA0
crw-rw---- 1 root uucp 204, 64 Apr 21 09:00 /dev/ttyAMA0

Disabling the Serial Console

The Raspberry Pi Arch Linux distribution is pre-configured to provide a system console over the serial port. You are unlikely to want this, as the serial port will be permanently attached to the DNT900 radio.

Disabling the serial console requires editing /boot/cmdline.txt. Remove any references to ttyAMA0 in this file. You’ll also need to disable the terminal service.

$sudo sed -i.old 's/[^ ]*ttyAMA0[^ ]*//g' /boot/cmdline.txt
$sudo systemctl disable serial-getty@ttyAMA0.service

Note that if you install the rpi900 package (as described in the next tutorial), this step is performed automatically.

Sending Data Manually

By default, the DNT900 is initially configured in transparent mode. In this mode, any characters it receives on the serial lines are transmitted via the radio link to the remote radio. The radio essentially operates as a ‘serial cable replacement’.

Use the stty command to configure the serial port prior to use in transparent mode. At a minimum, the data rate needs to be set; this will initially be 9600 b/s, the DNT900 default. (You can change this later.)

$stty -F /dev/ttyAMA0 9600

Depending on what device is attached to the remote radio, you may also need to set other parameters – raw mode, for example. For more information on stty, and a glimpse of the arcane world of TTY:

$man stty

Sending and receiving characters is then as simple as writing to and reading the /dev/ttyAMA0 device:

$echo "hello, world" > /dev/ttyAMA0  # send a message
$cat /dev/ttyAMA0                    # listen for a response

Flow Control

If you intend to send large amounts of data at high speeds using transparent mode, you will also need to enable hardware flow control on the serial port. This prevents data loss caused by overflow of the radio’s storage buffers. The rpirtscts utility lets you do this.

DNT900 Line Discipline

Instead of using the DNT900 in transparent mode, I recommend using the DNT900 line discipline to access all the features of the radio. This and other RPi900 software is available as pacman packages which are simple to download and install. The RPi900 package repository is the subject of the next tutorial.