For those who don’t know, the Raspberry Pi can transmit an FM signal directly. It’s a surprisingly powerful signal, too, and it’s very easy to do.
Following the guide on the Imperial College Robotics Society (ICRS) wiki, it took me less than 5 minutes to get the entire thing operational.
Step 1 – Download/Extract the Sample Code(GPL)
I am hosting a copy of their code located here. (this archive contains the source and binary).
wget https://daveconroy.com/SampleCode/Pifm.tar.gz
tar -zxvf Pifm.tar.gz
Step 2 – Attach the Antennae
Find an 8 inch piece of plain wire, and attach it to the GPIO4 port on your Pi. Technically the is step is optional, but my transmission range went from 200ft to 8 inches without it. Use the picture below as a reference.
Step 3 – Run the Code
Usage: sudo ./pifm wavfile.wav [freq] [sample rate]
The second command line argument is the frequency to transmit on, as a number in Mhz. For example, this will transmit on 100.1 FM
sudo ./pifm sound.wav 100.1
You can use whatever frequency you’d like (88->108).
That’s it! Here is a video of mine working.
How It Works
According to the ICRS, it uses the hardware on the raspberry pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM Radio energy.
For more information, and a link to the actual C code, visit the ICRS wiki. I’m also happy to answer any questions you have regarding my setup. Thanks!
Can this transmit RDS?
good question, I’m not sure!
https://github.com/ChristopheJacquet/PiFmRds
A good question would be if it is possible to use this to play any kind of streamed media. Or whether it is possible to stream input from external soundcard.
Can use this to play streamed media using xbmc
Can you please give more detail as how can this be achieved?
I can not for the life of me figure this out. Every time I try to run the “sudo ./Pifm” command, it just says the command was not found, and if I attempt to run it without superuser, it tells me that the file was not found, despite previously being CDed to the desktop, where the file was placed.
I’m not amazing with Linux, but I have used it before, but I cannot figure out why it’s doing this.
I had a similar issue. I had to do the following:
sudo chmod +x pifm
then it would run.
However, I just get noise on the rcvr. I can tell it is being generated by the pi, but it is just noise none-the-less.
Did you ever get it working, Larry? I too have the problem as you. I didn’t need to do the chmod, the pifm program runs fine, but no matter what frequency I try, all I get is ‘noise’. I KNOW it’s from the pi – Starts and stops when I start and end the program, but it’s “not” the audio file – Or rather, it is but it’s not playing it correctly.. Even tried specifying the sample hz (64000, 176000, etc). All I get is a garbled ‘tone’/staticy sound 🙁
Is it possible to move it from GPIO4 as I have my external temp sensor there and all the code is already written (Cron/websites ect).
Thanks
Sofa
Hi ya, in terminal type
ls
if you see the file in the list then your good to go, also remember Linux is case sensitive, pifm not Pifm
Sofa
Edit the pifm.c and compile it 😀
I wonder if one could use all three general purpose clock outputs to triple output power?
Could this be used to control an rc car, since the controllers usually just use 27mhz or 49mhz signals?
Great question! I bet it could!
Very nice !!!
Is it also possible to receive fm signal ?
Hi
This sounds very easy to implement, but it is not working for me. I tried this exactly as described above, but when I apply the command, I only hear a monotone sound from the speaker. This monotone sound stops when I stop the script by pressing ‘ctrl + c’.
I just did “$ sudo ./pifm sound.wav 100.1” to play sound and tune my fm-receiver on 100.1MHz.
Any idea why this happen? I appreciate for any suggestion.
Thanks
Wow, just wow. Thanks for this brilliant bit of software. Perfect as a teaching tool for schools etc. it’s like voodoo magic! Had it running in my classroom, I’ve never seen some of the kids so excited to judge just how far the FM signal would go!
Just one question, is it possible to PIPE into this program, I tried looking for a man or -h, but all to no avail. Been trying all sorts of audio magic and outputting it via the radio. Thanks a million, a brilliant idea!
it’s working. thanks man!
avconv -i http://mystream -ac 1 -ar 22050 -b 352k -f wav – | ./pifm – 108.0
how do i get OpenELEC to stream across PI FM?
to send a stream to pifm
Having no luck getting this to work on a Pi 2. It runs, but I don’t get anything on a nearby radio. I have to kill it with Ctrl+C.