Saturday, 1 November 2014

Using PiFM to transmit audio on any frequency up to 250 MHz

The first "hack" which allowed experimenters to use the Raspberry Pi's clock pin (GPIO 4) to transmit audio directly from the Raspberry Pi came from the Imperial College Robotics Society . Their "PiFM" module has since been modified and improved and is now capable of transmitting in 16 Bit Stereo on any frequency from about 1 MHz up to 250 MHz.

It sounds too good to be true.... so I decided to try it out for myself!

WARNING - DO NOT connect your Raspberry Pi's clock pin (GPIO 4) to any kind of antenna (even a short length of wire) when performing any of these tests!

Full details of the "PiFM"  module may be found here, and you can download it as a ".tar.gz" archive here. Once you have downloaded the archive to your Raspberry Pi, extract the files, open a terminal window on your Raspberry Pi and go to the folder containing the extracted files (in my case the Downloads folder). The folder should contain the flollowing six files:

left_right.wav           - sample stereo ".wav" file
sound.wav               - sample music ".wav" file (Star Wars theme)
pifm.c                       - pifm "c" source code
pifm                          - compiled pifm module
PiFm.pyc                 - Python bytecode for pifm                   - Python script for pifm

Position a VHF portable radio close to your Raspberry Pi and tune it to a frequency where there is no transmission (in my case 100.0 MHz). Type the following at the command line prompt in the terminal window (but enter whatever frequency you want to use) and press Enter:

pi@raspberrypi ~/Downloads $ sudo ./pifm sound.wav 100.0_

Almost immediately you should hear the Star Wars theme playing on your portable radio. You can stop playback by pressing "Ctrl+C" or you can let the music play right to the end of the ".wav" file. However.....PLEASE NOTE that in either case your Raspberry Pi will continue to transmit a carrier on the frequency you have chosen until it is rebooted or turned off, so please DO NOT leave your Raspberry Pi transmitting a carrier after you have finished experimenting!

I decided to have a look at the spectrum of the transmitted RF signal, however my spectrum analyzer only covers up to 60MHz so I set the Raspberry Pi to generate a 30MHz signal. The spectrum is shown below:

You can see the "fundamental" signal at 30 MHz, but there are multiple strong subharmonic and harmonic spikes all over the RF spectrum. I also noted that if I tuned my receiver to any multiple of 30 MHz (e.g. 60MHz, 90MHz, 120MHz etc) I could clearly hear the transmitted signal, sometimes very strongly.

Therefore please DO NOT connect your Raspberry Pi's clock pin (GPIO 4) to any kind of antenna when performing any of these tests, because you will generate unwanted and potentially dangerous RF energy right across the electromagnetic spectrum.

Whilst it is very easy to use the Raspberry Pi's clock pin (GPIO 4) to generate an RF signal, and even transmit audio, the usefulness of this hack is severely limited by the huge amount of harmonic and subharmonic distortion in the signal (because it is basically a square wave). I've read many articles which suggest the Raspberry Pi may be a used as a low power transmitter for the amateur radio bands simply by using a low pass filter on the output, but I'd say even this is insufficient (due to the subharmonic distortion in the generated signal). To make any practical use of any RF signal generated by the Raspberry Pi in this way would require very good band pass filtering.


  1. A hard disk media player that still has a cult reputation

  2. * On *my* system (Pentium 120) the following parameters:
    * 1000 1000 20000 20000 60 60
    * produce a sweeping tone on FM 87.5 MHz.
    * Berke Durak
    * 18081999


    typedef unsigned char u8;

    #define BUF_SIZE (1<<18)

    void tempest_cpu_pattern (int count, volatile int *buf, int a, int b)
    int i, j;
    int x1, x2, x3, x4;

    x1 = 0; x2 = 0; x3 = 0; x4 = 0;
    i = 0;

    while (count --) {
    for (j = 0; j> 4, b += (b2 - b1) >>4) {
    tempest_cpu_pattern (count1, c, a, b);

    return 0;

  3. Hi,

    I was just curious what you mean by "potentially dangerous". Is that dangerous to the Pi itself, other electronic devices, human health, etc? I was going to build one of these and use it around the house on a regular basis but after reading your post I'm a little wary now.


    1. Dangerous for legal reasons. Harmonic splatter causes the radio waves to emit all over the electromagnetic bands in which case potentially interfering with police, air traffic, ems, schools, busses, etc. if u do interfere, the fcc will most likely be at ur door in like... less than an hour.

  4. Wow, I have been surfing the internet for the past few hours and I have not come across such an interesting site with great content and a unique design. I have gain a lot from posted article and I have increased my general knowledge and I am very grateful that I landed on this site and found this great content. Access our site for affordable but Professional Editing Service.