Friday 12 June 2015

Raspberry Pi-rate Radio

Raspberry Pi-rate Radio

David Hayward takes to airwaves with a hacked Raspberry Pi

There are countless hacks for the Raspberry Pi these days. Such is the legacy of this remarkable little computer that if you can think of it, the chances are someone, somewhere, has modified the Raspberry Pi and bent it to the task. With this in mind, we were searching the other day for a suitable project; one that’s quick and easy but can deliver results, and among the many retro arcades, TV streaming appliances and other serving duties, we discovered a tutorial that can turn the Raspberry Pi into a powerful FM transmitter, allowing you to broadcast your own pirate radio station.


Making An Antenna


The first step in the process is to make the antenna. For this you’ll need a length of wire of around 50cm – you can go up to 75cm apparently, but any more than that will cause problems in the broadcasting. For our example, we stripped and used an old PC audio cable wire. It worked, but it wasn’t the most effective solution, so you’ll have to experiment with what you have lying around.

Start by attaching one end of the wire to Pin4 on the GPIO connector (GPIO 4), for our example we wrapped the wire around the pin and protected and held it in place, with a piece of wire tubing.

Software


The PiFM radio transmitter uses the already created PiFM Python script, from Imperial College Robotics Society as created by Oliver Mattos and Oskar Weigl. To install it you’ll to enter the following in the terminal first:

wget www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz

This will download the compressed files. You’ll need to unpack them next, with:

tar –xvf Pifm.tar.gz

Once everything is unpacked, you can start to play audio files, which will be transmitted on an FM band of your choice.

For the sake of this experiment, we’ll start by using the Sound. WAV file that came with the PiFM package. You’ll need to use sudo to play it, and you can specify the frequency in Megahertz at the end of the line. For example:

sudo ./pifm sound.wav 100.1

Will play the sound, broadcasting at 100.1. It’ll take a moment or two before you’ll hear anything, but you should get something through when you tune in to 100.1 FM – the theme for Star Wars!

Expand


If you have a selection of MP3’s to play, instead of WAV files, then you can easily convert the MP3 file on the fly using SoX sound exchange codec. Simply install SoX first, with:

sudo apt-get install sox libsox-fmt-all

Then once it’s installed, use the following command to play the MP3 at the same 100.1 frequency we used earlier:

sox –t mp3 NameOfTrack.mp3 –t wav –r 22050 –c 1 - | sudo ./pifm -100.1

With luck, the music should be played through an appropriately tuned radio to 100.1 FM. Obviously, you’ll change our Superman.mp3 to your own MP3. And to exit playing the content, just press Ctrl+C.

There’s More


If you have a podcast running, then you can also use SoX to broadcast the podcast through the PiFM module to your tuned in radio. All you need is the address of the Podcast as an MP3 – which most advertise – and to enter the following:

sox –t mp3 http://address.of.the.podcast.mp3 –t wav –r 22050 –c 1 - | sudo ./pifm – 100.1

And you also broadcast an online radio station by pointing SoX at its M3U file, with:

sox -t mp3 http://address.of.the.online.radio.station.m3u -t wav -r 22050 -c 1 - | sudo ./pifm - 100.1

Finally, you don’t have to use MP3 with SoX. If the broadcast or file is OGG, for example, just replace the sox –t mp3 part of the command line, with sox –t ogg.

A Big Hello To All You Truckers Out There…


One last element that’s worth mentioning. If you have a USB microphone handy, you can broadcast your voice over the radio waves by entering:

arecord -fS16_LE -r 22050 -Dplughw:1,0 - | sudo ./pifm - 100.1 22050

Unfortunately, we couldn’t try this part as we didn’t have a USB mic that would work or be recognised with the Raspberry Pi. That and the fact that we’d probably revert to our former 80s mobile DJ mode of speech stopped us this time.

Conclusion


There we have it. A simple, one wire and a bit of software solution to creating your own Raspberry Pi FM transmitter. However, we have to mention that if you’re to give this a go, then please take a moment to read through our disclaimer. Airband communications can be severally messed up with a powerful enough antenna and a transmission that uses the wrong frequency. And, as far as we can tell, the police take a very dim view on home users clogging up the airwaves with their own pirate music stations.

Disclaimer


As you no doubt read in the main body of the article, transmitting on FM frequencies can have a detrimental effect on commercial aircraft and tower transmissions. We’re not radio experts, so we can’t tell you for sure just how much damage a small strip of wire connected to a Raspberry Pi could do. Suffice to say, if there’s even a hint of trouble, you’re best off experimenting with caution.

Alternatively, you could always Google away and see if there’s a safe frequency to broadcast on. Or you could get in touch with a local radio expert or maybe even Ofcom, to ask for the details on how to do this without causing all sorts of problems with local flights and so on.

Also, on a more lighthearted note, if you do connect a USB microphone, please try to resist the urge to shout “Shabba!” down it every so often.