Raspberry Pi LogoLately I’ve been adding more and more to my home automation & security system. Some of the things I have been adding include installing Raspberry Pi’s inside the walls of my house so that each room will have its own embedded media center. When the RPi’s aren’t being used for playing media, they will be picked up and used by my cluster-server to get more horsepower when needed. While working with the Raspberry Pi’s, I recently came across an interesting article that shows how to turn the Raspberry Pi into an FM transmitter. I thought this was very cool and very simple to do. So, I wanted to share my success story with the rest of you.

I have already begun adding FM transmissions to my home automation system so that I can broadcast my music anywhere in the house and over any device as long as it can pickup an FM transmission which all of my stereo equipment does. I will also be using the RPi FM transmitter during the Christmas holidays where I will be automating my Christmas lights which will dance in sync with whatever song I have playing at the time. Passersby will be able to tune their car radio to the same FM frequency that I will be transmitting on so that they can hear the music along with watching the lights dance. I’m sure you’ve seen things like this before, but I thought it would be really cool to do this using the Raspberry Pi.

Well, enough of that. Let’s begin.

First off, if you have a Raspberry Pi, you already have everything you need to create your own FM transmitter. At my house, I am using the 512MB B Model of the Raspberry Pi which you can pick up from Amazon for about $42.00. Although it isn’t required, I would recommend that you also get some sort of wire which will be used as an antenna. If you do not add a wire / antenna, your transmissions will be limited to only a couple of feet. However, if you do add an additional wire / antenna, you will be able to broadcast up to a few hundred feet or more. The wire will need to be connected to GPIO4 to act as an antenna.

Once you have your antenna connected, log into your Raspberry Pi and download the PiFm application from the icrorobtics website or from my website by running the following command:

wget http://www.prodigyproductionsllc.com/downloads/Pifm.tar.gz

Note: The PiFm application includes a runnable binary as well as the C++ source code and an example Python app that can be used to call the binary. If you download my copy of the PiFm application, I have also included an additional Python script that extends the functionality of the provided Python application. For the purposes of this article, I will be referring to my extended version of the Python application, but you can also run the binary directly if you aren’t interested in Python. The only reason I’m referring to the Python app is because I am using it as part of my home automation system. So, this gives me some practice working with it.

Now that you have the PiFm application downloaded, you will need to extract it by running the following command:

tar -zxf Pifm.tar.gz

Next you will need to move into the PiFm directory.

cd Pifm

The runnable binary file is called “pifm”. My extended Python script is called “test.py”. Before you can run either of these, you will need to make sure that they have the correct permissions. You can make both applications runnable by executing the following commands:

chmod 755 pifm
chmod 755 test.py

You are now ready to run the application(s). Before doing so, you will want to have an FM radio nearby and have it tuned to the frequency you want to broadcast over. The application is capable of broadcasting between 1Mhz and 250Mhz. However, as stated on the icrorobtics website, most countries work best with frequencies between 88Mhz and 108Mhz. Also, it should be noted that most radio receivers need a single to be an odd multiple of 0.1Mhz in order to work properly. Example: 88.1, 88.3, 88.5, etc… For my tests, I chose to work with 87.3Mhz as there was no noise on this frequency in my area.

The PiFm application accepts 2 arguments or no arguments at all to use the default settings. The first argument is the name of the audio file you want to broadcast. Your audio files must be 16 bit mono wav format. If you do not have any audio files like this, don’t worry. The download above contains a test file called “sound.wav”. You can also use tools such as Audacity to convert existing audio to the 16 bit mono wav format if you want to use another audio file you may have. The second argument the PiFm application accepts is the frequency you want to broadcast on. If you try executing my Python app without passing any parameters, it will provide you with a couple of usage examples. To run the Python application, you can execute either of the following commands. Just make sure you replace the audio filename and frequency parameters with your own.

sudo test.py -s sound.wav -f 87.3
sudo test.py –song=sound.wav –freq=87.3


That’s it! If everything worked correctly, you should now hear your song playing over your radio’s speakers. Below is a video of this in action.

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.

Related Posts

Tagged with:  

Leave a Reply