Time signals have been broadcast by various radio stations for almost 100 years, usually “every hour, on the hour”, or every 60 minutes. The tradition was started by the BBC, but has been adopted by many national broadcasting companies and other broadcasters as a way of informing their listeners about the passing of time. The history of the Greenwich time signal, or “the BBC pips” is detailed in Mike Todd’s article.
This article gives you details on how to generate your own time signals using the Raspberry Pi. It assumes you have a RasPi up and running. It doesn’t really matter which hardware version, as this method should work on all of them (but do let me know if there are limitations – I’ve tested this on Raspberry Pi 3 Model B).
Originally I got the idea of replicating the broadcaster’s time signal from an article about the Finnish Broadcasting Company YLE’s version. Only later I realised that the Finnish version has been adopted straight from the original BBC time signal. If you’re Finnish, you should read the article “Yleisradion aikamerkki on radioklassikko” about the origins of the Finnish tradition.
First, install SoX
SoX, or Sound eXchange, is the Swiss Army knife of audio manipulation in UNIX-like environments. You should install SoX on your Raspberry Pi by issuing the command
sudo apt-get install sox
This command installs the basic commands used in this article. Wait until the command is finished, and then read the manual page with the command
Most of this will work as is on macOS, so if you’re on the Mac, use Homebrew to install SoX.
Shell script to signal time
Using SoX, it is trivial to generate the basic ingredients of the the time signal. From sources we know that it consists of five short 0.1 second beeps, interspersed with 0.9 seconds of silence (so that each pip lasts for exactly one second), followed by a final beep of 0.5 seconds. Each beep is a sine tone with a frequency of 1000 Hz.
A tone like this can be generated and played using the SoX play command:
play -n synth 0.1 sin 1000
The use of a ‘null file’ with the -n parameter is sort of implicitly documented, but once you know that the name ‘synth’ generates audio, you can find the parameters easily in the man page. And, as you would expect, the synthesiser can do a lot more than generate sine wave beeps.
Using the play command and the UNIX sleep command together makes it trivial to write a small shell script to replicate the whole time signal. Open a programming editor and save the following as ‘pips.sh’:
#!/bin/bash # file: pips.sh play -n synth 0.1 sin 1000 sleep 0.9 play -n synth 0.1 sin 1000 sleep 0.9 play -n synth 0.1 sin 1000 sleep 0.9 play -n synth 0.1 sin 1000 sleep 0.9 play -n synth 0.1 sin 1000 sleep 0.9 play -n synth 0.5 sin 1000
Now you can run this in your terminal with the command:
Or, you can give it executable rights with:
chmod u+x pips.sh
And run it with just:
If you have connected the audio output of your Raspberry Pi to a speaker, you should hear the time signal beeps. I’m using a Tivoli Audio PAL with the RasPi connected to its AUX IN with a standard audio cable. I also selected Audio from the Raspberry Pi graphical user interface. You should also be able to get HDMI audio; refer to the Raspberry Pi audio configuration page for details.
Timing the time signal
You could use the
at command on the Raspberry Pi to run a command (like a shell script), but that would run it only once. We need a way to run the
pips.sh script repeatedly.
In UNIX-like environments you can schedule a command using
cron. It is not a command, but a system daemon that consults its own table called
crontab to determine what commands to run and how frequently. For a basic overview, read Scheduling tasks with cron on the Raspberry Pi website.
cron works on a per-user basis, so be sure to edit the right user’s
crontab file. Typically, when you’re logged in and you want to edit your own crontab entries, you just say
If and when you are prompted to select and editor, I recommend that you select
nano. If you’ve never used
nano before, you only really need to know two commands for now, Ctrl + O to save the file, and Ctrl + X to exit (both are shown for you at the bottom of the screen).
After you have edited the crontab file, you can check your scheduled jobs with
crontab -l; effectively it just dumps your
crontab file on the screen.
When I was testing this solution, I didn’t want to wait for an hour to find out if my crontab entry worked, so I used the “every minute” option. My
crontab entry thus looks like this:
* * * * * ~/Projects/TimeSignal/pips.sh
To actually run hourly, use
0 for the minutes. Also, if you want to restrict the time signal to office hours (say from 8 a.m. to 4 p.m.), specify the hours also, like this:
0 8-16 * * * ~/Projects/TimeSignal/pips.sh
cron manual page (with the command
man cron) for more details, and use the cron sandbox to test your entries.
There is one problem, though:
cron does not deal in seconds, but the time signal should be started six seconds before the hour. Currently I don’t have a solution to this, but if you do come up with one, let me know.
When I started to write this post, I realised it has been a year since the last one. Wow. Let this topic be a signal to mark the occasion. Note to self: must blog more often.
Also, coincidentally, yesterday was Pi Day (because in some cultures the date is expressed as 3.14 or 3/14, which is a poor substitute for the estimated value of pi, but I digress). Besides, Stephen Hawking passed away yesterday. May he rest in peace.