Building a Digital Mobile Radio Repeater Part 4: Raspberry Pi Configuration
Setting up the Raspberry Pi and MMDVM Host software.
This series of posts covers the building of a Digital Mobile Radio (DMR) repeater for amateur radio use on the 70cm band (UHF). The first post introduced DMR basics and a modem platform based around an STM32F446 NUCLEO board plus an interface shield. The second covered the major and housing these all in a rack enclosure, with the third moving on to cabling.
In this post, we take a look at configuring the Raspberry Pi and installing MMDVMHost software, which will drive the repeater and facilitate connection to global repeater networks via TCP/IP.
Most good Raspberry Pi projects start out with similar steps and so to lets quickly cover what has now become something of a mantra (assumes you’re using a Linux computer):
- Write out Raspbian to a Micro SD card
- Remove it from the computer and re-insert
- Edit the
etc/hostsfiles on the root partition to set a new hostname
- Create an empty file called ssh on the boot partition
- Unmount and remove the card
- Insert the card into the Raspberry Pi
- Boot the Pi and log in
sudo apt-get updatefollowed by
sudo apt-get upgrade
In our case we used a hostname of repeater and logged in over SSH, using the mDNS hostname, repeater.local. Of course, you could use a keyboard and monitor if you prefer. If you used a Windows computer to write out the card and didn’t have a Linux one to hand, you could edit/create the aforementioned files after booting and logging in via keyboard and monitor.
Status and shutdown
As mentioned previously we need a mechanism whereby the Raspberry Pi can be safely shut down without a keyboard and monitor attached, or perhaps by someone with no Linux experience at all.
In part three we described how the front panel pushbutton was wired across one GPIO pin and ground, while the status LED above it was wired across a second GPIO and ground with a resistor in series. Thanks to the magic of device tree overlays these will allow us to shut down the Pi safely at the push of a button and to confirm status via the LED.
To configure this we simply edit
/boot/config.txt and add three lines:
dtoverlay=pi3-act-led,gpio=12 dtparam=act_led_trigger=heartbeat dtoverlay=gpio-shutdown,gpio_pin=16
The first of these loads the activity LED overlay and configures this to use GPIO12. The default behaviour is for this to indicate SD card activity, so the second line configures the LED instead to provide a system heartbeat, meaning that we can quickly ascertain if it’s running or halted.
The third line in config.txt loads the GPIO driven shutdown overlay and configures this to monitor pin 16. If this is pulled low, shutdown is triggered.
Having these sort of capabilities available via device tree overlays is very cool and configuration couldn’t be simpler — no need for additional software or building custom kernels/modules.
For details of all the available DT overlays, see the Raspberry Pi Firmware overlay README.
First, we need to install a few dependencies:
$ sudo apt-get install build-essential git
Then we can clone the MMDVHost software sources:
$ git clone https://github.com/g4klx/MMDVMHost.git
Next, we cd into these and build with:
$ cd MMDVMHost $ make
And if all goes well this should complete without errors.
The included example configuration file,
MMDVM.iniwas modified to set the following parameters:
[General] Display=Nextion [Modem] Port=/dev/ttyACM0 [Nextion] Port=modem
Note that only the modified parameters and their sections are shown — just enough for some basic testing and a lot more configuration will be required later.
Then we could run up the application with:
$ sudo ./MMDVMHost MMDVM.ini
The application couldn't communicate with the MMDVM firmware on the STM32F446. Something wasn’t right...
After a little head-scratching, it was decided to remove the STM32F446 and MMDVM shield from the enclosure for closer inspection. Upon separating the two boards and looking at the headers, it became apparent the shield had been plugged into the wrong side of the STM32F446!
The shield was promptly swapped over so that the STM32F446 Mini USB port was on the outside and not located between the two boards.
The Pi was booted and this time things looked much better, with LEDs on the shield illuminating and the Nextion from panel LCD springing into life.
Starting, stopping and restarting
There is no MMDVMHost make install target and configuration for automatic start-up is a fairly manual process. When configured to run in daemon (background) mode an mmdvm user account and group are required for it to switch to, so we’ll create these first.
$ sudo useradd mmdvm -G dialout -m -s /bin/false
Oddly, it seemed that we also needed to add the root account to the dialout group, otherwise the application was unable to open the modem.
$ sudo usermod -G dialout -a root
Next, we created a directory each for the configuration file and logs.
$ sudo mkdir /etc/mmdvmhost $ sudo mkdir /var/log/mmdvmhost
We then copied the executable and config files into place.
$ sudo cp MMDVMHost /usr/local/bin $ sudo mv MMDVM.ini /etc/mmdvmhost
A service handler (start|stop|restart) script is provided, but we found we had to modify this a little. Firstly, to specify the full path of the config file and not just the directory it is located in. Secondly, to execute the application directly and without “runuser -l”; the app will switch to the mmdvm user and group by itself, and runuser caused problems. The logfile location was also changed.
So once copied into place with:
$ sudo cp linux/systemd/mmdvmhost_service /usr/local/sbin
runuser -l $ USER … lines were replaced with simply:
And the lines for the aforementioned variables were updated accordingly:
This file will also need to be made executable:
$ sudo chmod +x /usr/local/sbin/mmdvmhost_service
At this point if Daemon=1 is set in MMDVM.ini we should be able to start, stop, restart and check the status of the modem service with:
$ sudo /usr/local/sbin/mmdvmhost_service start|stop|restart|status
Now all the parts are in place, next we will need to configure the repeater as a whole system:
- Radio programming, e.g. for Tx and Rx frequencies.
- Full configuration of MMDVMHost, e.g. repeater call sign and network connections.
- Flash the Nextion LCD configuration (different screen layouts are supported).
- Setting modem audio levels.