Run Your Very Own Radio Station with the Raspberry Pi

You can use the Raspberry Pi for a variety of geeky projects. But I recently found out that you could use the puny little device as a FM transmitter as well. And that do without much tinkering.

A bunch of folks over at Code Club pihack wrote a program to use hardware on the Raspberry Pi that’s meant to generate spread-spectrum clock signals to instead output FM Radio signals.

Here’s a bit of background. Besides the familiar Audio, Ethernet, HDMI, and USB ports on the Raspberry Pi, the device also has interfaces that are designed to to connect more directly with other chips and modules.

These General Purpose Input/Output (GPIO) “ports” are the 26-pins (arranged in a 2×13 strip) you see on the board. These interfaces are not plug-and-play but can controlled through software.

To transmit a surprisingly strong FM signal, all you need is to attach a wire to the GPIO 4 pin. Even without the wire, the FM signal broadcast by the Raspberry Pi will be picked up by nearby FM receivers.

pifm-gpio

A word of caution: The laws for broadcasting FM signals varies from country to country. Please check your local regulations before attempting this project.

Power up the Pi and head to the command-line either via SSH or by directly logging into the device.

We’ll now grab the code written at the Code Club hackfest and extract it:

The directory now contains six files. Surprisingly that’s all there’s to it. You can now broadcast the included “sound.wav” file:

Now grab a FM receiver and set it to FM 102.3 and you should hear the Star Wars theme music. You can actually change the broadcast frequency from anywhere between 88 MHz and 108 MHz simply by appending the channel frequency at the end of the command.

pifm-rpi

You can play other audio files as well, but they must be 16-bit 22050 Hz mono and in the WAV format only. That might seem like a real limitation but it really isn’t. All you need is the SoX sound exchange audio editor which will process your MP3 file and convert it into the WAV file on-the-fly.

Install the audio editor and its dependencies with:

When it’s done, type in the following command, substituting “SomeSong.mp3” with the name of the MP3 file you wish to play:

The first part of the command translates the MP3 file into a WAV file, changes its audio sampling rate to 22050 and down-mixes the track to mono. The converted track is then sent to the standard output, denoted by the hyphen sign (-) and is then piped (|) into the standard input of the pifm command.

The only difference in the pifm command in the above example is that instead of specifying the name of the file to broadcast, we are asking the script to instead broadcast the standard input.

If you’ve still got your FM receiver tuned to the 102.3 frequency, you should now hear your MP3! Again, just like the original example, feel free to replace the frequency to anywhere between 88 MHz and 108 MHz.

You can do some wonderful things with SoX. You can, for example, use it to broadcast your favourite streams live from the Internet.

To broadcast the Linux Voice podcast:

The only difference between this command and the previous example is that instead of pointing to a local MP3, you are now pointing to one that resides online.

You can similarly broadcast an online radio station. Many stations publish a M3U file and you can point to it:

Not all stations broadcast MP3 streams. Some use other formats such as OGG. All you need to change the type of the input file you are converting with sox. Such as:

If you’re looking for online radios, here’s a huge list of European radio stations that stream online.

Image credit: Robert Ashworth

5 comments

  1. This article may contain a hint to solve a problem with my Raspberry Pi. I am a beginner with the R-pi and just started setting it up. I have it connected to a Vizio TV on the wall in my computer room via HDMI. This room is one floor below the Family room where there is another Vizio TV. Both TV’s use a Bluetooth remote control. What is happening is while the Pi is operating the input selection of the Vizio TV in the Family room will randomly change. The 2 TV’s are electrically connected to both my MATV distribution system for over the air TV signal and also through an HDMI splitter from my Dish receiver. So there may be a path for a Bluetooth signal generated by the Pi to affect the Vizio TV in the Family room. However, I do NOT have either a WiFi or a Bluetooth adapter connected to the Pi. But, if it can generate an FM signal on the 88-108 Mhz band could it be emitting a harmonic signal in the 24Ghz band? I have not yet started to research more deeply into this such as disconnecting the computer room TV from the HDMI splitter or MATV system, or using a different HDMI input or switching to an analog input. But, this article sparked some interest in my mind and I was wondering what the possibilities are.
    Michael

  2. Hi,

    Looking for a solution to a problem, i n my country secondary schools are being encouraged to create school radio stations, problem is the cost of equipment. I’ve had my pi for a while, (got it ordered on that faithful morning in Feb), this looks like a really cheap effective and cool solution, but i would like to be able to use a Mic or even produce a show on my main machine and just use the pi to transmit., anyone got a solution?

Comments are closed.

Sponsored Stories