PI4 GPIO PTT via Hamlib (rigctld)

Well I had the bright idea that I would simply rebuild my audio isolation box and add a relay to key the PTT circuit with the PI’s GPIO pins for digital modes since the IC-730 doesn’t have a traditional rig control.

Well that has turned into a whole adventure. First was designing and building the box. I’ve got it working and built and man this box looks so much nicer than the old large plastic box. But this also came with a few challenges.

  1. Fitting all the connections needed was a bit of a challenge in the size box I chose. Mostly due to my selection of styles I think.
    1. Audio in (1/4 MONO) from rig to audio isolation transformer
    2. Audio out (1/4 MONO) from audio isolation transformer to mixer
    3. PTT (1/4 MONO) foot or hand ptt switch
    4. MIC (1/4 MONO) from mixer digital & phone comes here
    5. PI CONTROL (3.5mm STEREO) this is the 3 wires the relay needs from the PI’s GPIO
    6. 8 PIN Aviation Mic Connector PTT and mic connection back to the front of the rig makes it universal for later if I change older rigs
  2. Fitting a 3.5mm stereo connector in the side of the PI’s case wasn’t too difficult aside from the care it took to make sure when it closes nothing gets interfered with electrically or mechanically causing catastrophic shorts. Had to file down the case thickness to accommodate the small connector’s ability to pass through material. Remember ground goes to Sleeve (this is important later)
  3. Testing the PTT circuit before I put everything together was going well until I plugged in the PI, and I found a couple of my own errors.
    1. remember the ground goes to sleeve? Yup don’t confuse that or the pi will be really unhappy. whoops!
    2. Radio keyed when pi was plugged in but not when it wasn’t. This one had me scratching my head until I realized that I had ground from the rig’s pin connected to tip on the mic switch at the relay. This didn’t cause an issue until the PI was in the circuit and it completed the ground loop I had in inadvertently created. No problem swap a couple of wires around on the relay and put ground with ground and we are good!
  4. Next came testing signals, with a python script I was able to key the PTT via the GPIO, and this made me really happy. BUT the issues arose after this point!
    1. First at the time of this publishing, the version of wiringpi package doesn’t support the PI4B so you need to download and install the updated library. Instructions and link here: http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/
    2. Didn’t see any information in the man pages (maybe I over looked it) on using GPIO in hamlib. Whoops shoulda checked this. Anyway lots of googling and Came across this thread on hamlib’s github page, and off we go! We’ve got the command for GPIO an undocumented feature.
    3. Next came the challenge of getting rigctrld to talk. But first, after talking with a hamlib dev, we need to verify that rigctrl -P GPIO -p 17 works with my chosen wiring of using GPIO pin 17 to key the relay. And behold, it does! Hmm why doesn’t rigctrld like it? I mean it keys with python, it keys with gpio, it keys with rigctrl! Back to the devs. Well after much discussion with the devs of hamlib I came to the realization that I needed a newer version of rigctld, as they were suggesting using rigctld-wsjtx and it was not in the repository for raspian buster. So off to gethub to get their current master build source code and build from source. The steps to build from source are outlined below. After building the hamlib package from source and a small change to my start script (also below) I’m off and running! Yes it was simply that I needed the newest version of hamlib and now I’m keying the IC-730 with hamlib and not fighting the challenges of using VOX keying for digital modes! I’ll add a few LEDs for indication to monitor the computer signals for later diagnosis if there ever is an issue.

Building hamlib from source you’ll need to run these commands from the command line interface (cli):

Let’s make sure we have the tools we need

sudo apt-get --yes install git build-essential

Get the latest version of the source code from the hamlib devs this is the main branch

git clone https://git.code.sf.net/p/hamlib/code hamlib-code

Change into the directory where the source code was just downloaded

cd hamlib-code

Building the source code using GNU tools:

configure the package

./configure

make the bianaries

make

perform the install

sudo make install

configure the libary paths that were just made and installed, important don’t miss this step or you’ll get errors and hamlib will not run

ldconfig

In my case starting rigctld is done with a cron job script that runs the below command. You can run this command from cli for testing purposes. To explain what this command does, /usr/local/bin/rigctld is the location of the rigctld binary from the build, I still have the repository’s version in another location on the PI so at some point I’ll have to remove it, but for now things work fine. -P GPIO tells rigctld that we are using the GPIO pins to key the PTT and -p 17 tells rigctld what pin is running the PTT.

    /usr/local/bin/rigctld -P GPIO -p 17

Here’s my start script that runs every minute the computer is on and assures that rigctld is up and running ready to operate. rigctld will never be down for more than a minute. Use your favorite cli text editor to create a file named rigctld_start.sh I use pico.

pico ~/rigctld_start.sh

Now paste the script below into the cli editor (shift insert) and save. Remember I chose GPIO 17 to key my relay. Adjust accordingly if you have chosen something different.

#!/bin/bash
sleep 2
a=$(pidof rigctld)
	if [ "$a" != "" ]; then
		date >> /tmp/start.log
		echo "Already running." >> /tmp/start.log
	else
		date >> /tmp/start.log
		gpio -g mode 17 out
		gpio export 17 out
		/usr/local/bin/rigctld -P GPIO -p 17 &
		echo "Started." >> /tmp/start.log
	fi
echo "---------------------------" >> /tmp/start.log

Change the permissions to rigctld_start.sh to make it executable.

chmod a+x ~/rigctld_start.sh

Move the script into /usr/bin/ to make it executable from cli from anywhere and easy

sudo mv ~/rigctld_start.sh /usr/bin/

Now the cron job is easy to set up, you can do like I did and follow the instructions here and edit it directly in cli easy enough. Here’s a snippet of the line you’ll need from my cron tasks. My home directory on the PI is /home/pi/ yours may be different. The ~/ above refers to your home directory. Use absolute paths and not ~/ reference in cron.

* * * * * rigctld_start.sh > /dev/null 2>&1

Finally in order to use this you need to configure all of your software that you want to key the radio to use “2 HAMLIB NET rigctl” an example of wsjtx is below.

Here’s the schematic. I have not added the audio isolation into this schematic yet as I’ve not yet completed the calculations to bring the 600ohm audio isolation transformer down to 8ohm without using R, something I do not want to do as I don’t want to bleed off any of the 2w or so that most radios have as audio output power.

SCHEMATIC
Ardrino_SPDT_Relay_Board1SunFounder Relay Module for Arduino and Raspberry Pi 5V DC Trigger by HIGHLO (HIGH Trigger)1
C20.1uF1
GPIO3.5mm stereo1
MICROPHONE1/4 mono1
PTT1/4 mono1
RIG8 PIN AVIATION MICROPHONE CONNECTOR1
T2Transformer_AUDIO 600:6001
D1LED GREEN1
D2LED RED1
ENCLOSUREJIUWU Surface Drawing Split Aluminum Enclosure Project Box Electronic Enclosure Case for PCB Board DIY, 88x38x100mm (WHL), Black1
BILL OF MATERIALS

Maybe I’ll even figure out using a GPIO for reading the VFO frequency in CQRlog, man wouldn’t that be nice?!!

Leave a Reply

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