The author was chief engineer of KUPL(AM/FM) in Portland, Ore., and WBSB(FM) in Baltimore; assistant chief of WTTG(TV) in Washington; broadcast service center manager for Sony; and senior systems engineer for DiviCom.
After retiring to a rural area from a radio and television engineering career in major markets, I discovered the world of very small-town radio.
Most of these stations, once with several employees and at least one engineer, now get by with the owner and a small handful of staffers. I haven’t seen a full-time engineer in ages. Engineers in nearby larger markets are called for help. It’s expensive and hard on the engineers, who generally have full-time work and often would rather spend evenings with family and hobbies.
Given the stability of modern transmitters and program automation, it seemed that it wouldn’t take much to automate some of the more trivial tasks and reduce the number of service calls. While pondering inexpensive ways to simplify operations, the Raspberry Pi came to my attention. This $35 quad-core wonder, intended to help children learn to write code, seemed the ideal way to become familiar with more modern languages, in my case Linux and Python, and do something useful to boot.
Python 3 is well-suited to this sort of task; it’s an interpreted programming language and doesn’t have a compilation step, so tweaking the program is quick and easy. Case-sensitive programming languages can be a pain in the neck and a lot of time can be spent chasing typos. (Don’t ask how I know this.) Being able to spot a flaw in the code, correct it and run again quickly is a major timesaver.
The first project was a simple network-connected time-clock to handle power changes dictated by the station license and to recover from power outages common in this lightning-prone area. One station has three “time zones”: day, critical hours and night. The other has day power plus an hour at reduced power after sunset. All I needed was a RasPi, a relay module and an LCD readout to show that the script was running and the system clock was being kept accurate.
The beta unit is shown in Fig. 1. It features a RasPi 2, generic four-relay module and PiFace display. The total cost was well under $100. I opted for Ethernet instead of Wi-Fi, as you never know when a change in vendor or router will result in a new password or network domain, disabling access. For those who can depend on their local network’s stability, the RasPi 3 has built-in Wi-Fi.
The Python 3 script is straightforward. The system boots into the script at power-on. After initializing, the unit trips the relay for the power level at the current time. This was included so that if a power outage spanned a power change time (say, day to night), the right power would be set at restart. Network Time Protocol (NTP) keeps system time accurate and pytz, the world time zone library for Python, handles time zone and daylight time issues. Entering the local station’s time schedule (24-hr standard time) takes a while, but is the heart of the system.
Having a couple of years of trouble-free operation, and a degree of confidence in these devices, I decided to expand their scope. To ensure that I could assemble them quickly and reliably, I chose to use plug-together modules, as seen in Fig. 2. I’ve left the assembly “open” and unenclosed, both for ventilation, and ease and speed of repair should it be necessary. Painting, drilling and assembly are time-consuming and costly. Remember, we’re working on the cheap.
The next stage was to add an analog-to-digital converter (ADC) module. Now we can monitor the transmitter and send a text message to the appropriate person if tolerances are exceeded. The ADC cards from AB Electronics come in single-ended models (0 to 5 volts) and differential models (–2.048 to +2.048 volts). Each features eight channels of 17- or 18-bit resolution respectively. I used the single-ended model for the prototype.
The relay module is a Relay Plus from PiFace, which, with the LCD display, completes the unit.
After I wrote the first draft of this article, Hurricane Matthew breezed through and revealed an oversight. The Raspberry Pi lacks a real-time clock; when power was restored to the stations, internet service was still out and thus the RasPi clock couldn’t be locked to a time source. This caused the controller to run with an arbitrary, unsynchronized time of day until the internet service was restored. The solution was a real-time clock (RTC) card from AB Electronics. At around $12 and a half-hour to add, it nicely fit the requirement.
Fully assembled, the expanded controller cost less than $175. Fig. 3 shows the enhanced prototype. Mounted on a piece of acrylic, the modules from bottom up are the Raspberry Pi 3, AB Electronics RTC, AB Electronics ADC, PiFace Relay Plus card (four-relay module) and on top, the PiFace LCD module.
M2.5 standoffs are used to fix the modules in place; 10 and 15 mm male-female, brass or nylon work well. Where a longer standoff was needed, I threaded two together. Before assembling, you must move jumpers on the ADC card, as it shares the same i2c address as the RTC. The ADC is shipped as Configuration 1 in Fig. 4. Simply move two of the jumpers as shown in Configuration 2.
Before we look at the Python 3 script, a reminder: This is novice coding. The object of the exercise was for me to learn modern programming languages. It’s much better than the spaghetti code of my youth, but the experienced eye will see at least a few places where last-minute fixes could use improvement. It’s a work in progress; more features are planned and code cleanup is ongoing.
The initial setup process for the RasPi is well documented on the web, so we’ll begin assuming that memory has been expanded, time zones, languages, keyboards and the like have been set up. The current Linux operating system for RasPi named “Jessie” has a streamlined configuration program that simplifies the process. Be sure to use the Interfaces menu to enable SPI (the Serial Peripheral Interface bus) and I2C (the Inter-Integrated Circuit bus). Note the RasPi must be connected to the Internet for the following steps.
Log into a RasPi terminal session and enter the following boldface commands (bearing in mind that this is case-sensitive and each command is on a single line):
sudo apt-get update
sudo apt-get upgrade
(These commands update and upgrade the RasPi. Enjoy a cup of coffee and catch up on back issues of Radio World; this can take a while.)
sudo apt-get install python3-smbus pytz python3-pifacecad python3-pifacecadrelayplus
(The above command is all on one line. This command installs python 3 and its supporting libraries.)
git clone https://github.com/abelectronicsuk/ABElectronics_Python3_Libraries.git
Now we need to relocate two files so that the script can import them.
In a folder called /home/pi/ABElectronics_Python3_Libraries/ADCPi
Locate the two files ABE_ADCPi.py and ABE_helpers.py
Copy them to /home/pi/ (this is the same directory where your xmtrctrl.py script will reside.)
Finally, we’ll provision the Real Time Clock board, but first, ensure that the hardware is working:
sudo apt-get install i2c-tools
sudo i2cdetect -y 1
The i2c table should show devices at 0x68 (RTC), and 0x6a and 0x6b (ADC).
Enable RTC time at bootup by editing the boot configuration file with the nano text editor.
sudo nano /boot/config.txt
Add the following to the end of /boot/config.txt, then save and close the file.
Reboot the RasPi for the changes to take effect.
Login to a terminal session and enter the following:
sudo i2cdetect -y 1
If all is well, you should see UU at address 68.
Now we disable the RasPi’s fake clock:
sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
With the fake clock removed, we can start the hardware RTC, by editing the hwclock-set file using the nano text editor.
sudo nano /lib/udev/hwclock-set
Comment out these three lines near the top of the file by adding a hash (#) mark at the beginning of the line:
#if [ -e /run/systemd/system ] ; then
# exit 0
Finally we set the clock. This only needs to be done once. From now on it’s automatic:
Check the display and see that the time is close to correct.
sudo hwclock –w
(to write the time to the hardware clock)
sudo hwclock –r
(to read the time from the hardware clock)
That’s it. The next time you reboot, the time will be set whether or not the internet is available.
Having assembled the system and prepared the computer, it’s time to load our transmitter control script into the /home/pi directory.
To test the system prior to connecting the transmitter, I built a transmitter simulator (Fig. 5). This is simply a three-relay (interlocked) board that sends a voltage appropriate for the mode to the RasPi’s ADC.
After you’ve installed the control script (e.g., xmtrctrl.py) in the /home/pi directory and have it working, you can set the RasPi to run the script at boot time by telling the system to do so.
Login to a terminal session and enter the following to create a new file using the nano text editor.
sudo nano /lib/systemd/system/xmtrctrl.service
Add the following text to this new file:
Description=Transmitter Control Service
Save the file and close nano.
Enter the following commands to change the file’s permissions and tell the system to recognize this new file.
sudo chmod 644 /lib/systemd/system/xmtrctrl.service
sudo systemctl daemon-reload
sudo systemctl enable xmtrctrl.service
To check if your new service is running, enter this in a terminal session:
sudo systemctl status xmtrctrl.service
BILL OF MATERIALS AND PRICES
(Cost may vary.)
1. Raspberry Pi 3$35. a. 5v, 2.5A power supply with micro USB plug$10. b. Micro SD card (8GB – Class 10 works well)$10.2. AB Electronics Ltd ADC Pi Plus board$21. a. Add a 0.1” 8×2 male-male header for inputs3. PiFace Relay Plus board$26.4. PiFace Control & Display board$35.5. Barrier Strip$6.6. AB Electronics Real Time Clock module$12.7. CR2023 Lithium Battery for RTC module$5.Total (plus tax, tags, freight)$158.
The prototype is mounted on a 5x4x1/4” acrylic plate. The finished product will mount on a 2RU panel or (with a mounting adapter) a DIN rail.
A supply of 2.5 mm hardware is useful, nuts, screws, washers and standoffs (10mm & 15mm female to male).
A labor-saver with Linux “Jessie” is the SD Card Copier. Once you have everything running the way you want it, make a copy of the SD card to another SD chip … or two. Building a duplicate system or just having the chip for an emergency spare is a good idea.
The Raspberry Pi can be run “headless” — no monitor, mouse or keyboard needed. Using SSH, one can log in from anywhere on the network and check system operation. If you’re running Microsoft Windows on other computers, you can download and install PuTTY, a free SSH client, available from www.putty.org.
Although I haven’t tried them myself, there are a several ways (VNC, for one) to run the RasPi’s desktop on a remote computer.
Now that the basic system has shown itself reliable, the next step will be to add a web server to the Pi and make it possible to access parameters and issue commands (if security is sufficient) from a browser.
With that enhancement, expanded capabilities present themselves, Monitoring more parameters (tower lights, silence sense, DA performance, ambient temperature) and checking the status of various tallies are a few. If you have more than one station to look after, it would be fairly straightforward to aggregate information from them to give real-time status reports.
For facilities without consistent access to the internet, GPS could substitute for Network Time Protocol (NTP). Fault reporting might be by cell phone or landline. If you use GPSD to replace NTP, some fairly minor changes to the script would be needed. Compatible GPS modules are inexpensive and readily available.
As the Raspberry Pi ecosystem — already robust — expands, off-the-shelf solutions for monitoring and automation functions become more economical and easily implemented. The modules I’ve used can be found at various vendors and eBay. There are a lot of stations with antiquated remote control and monitoring systems. Replacing them (or repairing a serious fault) could break most small-station budgets. Quickly assembled, readily programmed replacements can be a lifesaver.
Do you have a Raspberry Pi story? Write to firstname.lastname@example.org.