Raspberry Pi Radio Transmitter

267,320

299

132

Posted in TechnologyRaspberry-pi

Introduction: Raspberry Pi Radio Transmitter

About: Love to see what makes things tick! email me at: CodyJHeiser@gmail.com

The Raspberry Pi is a very useful computer that can be used for many different things. The people over at Imperial College Robotics Society have a new way to use your favorite treat. They designed a program that turns the Pi into an FM radio transmitter. This instructable will show you how to make your own Pifm transmitter, installing and using the program.

Some Updates (03/11/15):

There is a new program up that I wrote where you only need the filename (NOT THE PATH). It will install everything for you, all you have to do is type in the frequency and the filename to be played (WAV or MP3, stereo or mono). github.com/CodyJHeiser/PiStation

ICRS has released another version on PiFM a while back, it allows you to play stereo sounds (mp3 files) over the radio now. You can go to this link here to check out the new information (the new code is included in my program listed above.)

More Updates (08/06/15):

The member, AndrewG29, has given me a link to GitHub that supports the Raspberry Pi 2! Through the traditional method, this doesn't work on the RPi2.

Step 1: Having the Necessary Parts

Obviously this will not work unless you have the right parts to start your Pifm radio. I will list the basic things that you need to start up your Raspberry Pi that most of you already have, but I will put it there for the people that don't.  In the second paragraph are things that you may not have that you need.

1. Raspberry Pi
2. 5 volt 1 amp (between 750 milliamps and 2 amps is what I have tried) USB power supply
3. Micro USB cable
4. At least 2 GB SD card with Raspbian on it
5. A display or ssh 

Now past the basics, you will need these items as well for it to work.

1. Ethernet cable or a wifi dongle (See step two if you don't have this)
2. Some sort of antenna
You can just use your finger but it will not work as well, you can use a Pi Cobbler with some wire sticking out of the pin like I did, it works fine, the projected range is about 10 meters, but I found it to go much longer than that.

Step 2: Downloading the Packages

Now that we have everything we need, we can get to installing the software, it is a very simple process.  Keep in mind that this will not work if you are not connected to the internet (see below**).  You only need the internet to download the software, you can use this afterwards without internet.

** If you have an Ethernet cable you can ignore this paragraph.  If you don't have an Ethernet cable but you still want to do this you can download the files onto your computer and put it on a flash drive and upload it to the "pi/home" directory.

Now in your Pi terminal type in this exactly, pay attention to capitalization!

     wget www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz
(Capitalized 'P' in 'Pifm.tar.gz')

     ls
(If you did it right when you type 'ls' you should see other files along with one named, 'Pifm.tar.gz')

     tar -xvf Pifm.tar.gz
(Again, capitalized 'P' in 'Pifm.tar.gz')

     
That's it!  All of the code is done, now on to the next step to learn how to actually play music over any station you want.

Step 3: Using the Software

Finally we are to the end of our journey, but all of this hard work pays off when you can impress your friends with your awesome new 'hacking' abilities!

There are a few commands that are used to control the pi I will list them below and break them up and tell you what they mean step by step.

Before we get into the code, you need to know what pin it broadcast's out of so you can attach your antenna to it.  GPIO pin 4 is what is being used, unfortunately you can't change the pin number because it have specific specifications embedded into it, so if you have something else running out of GPIO pin 4, you will have to change it or take it out for this to work.

     sudo ./pifm sound.wav 100.1

          sudo - This gives you administrator power (like on windows the admin)

          ./pifm - The ./ is used to run a program, the program you want to run is what you put after it (pifm)

          sound.wav - Here is the music you want to be played over the radio, you can change it to any** .wav file
          100.1 - This is the station that you want your music to be played on, you can change this to anything between 87.1 and 108.1

To exit your song press, 'control' + 'c'

If you have a microphone you can plug it into the USB port and broadcast your voice over the radio station here is what you will type in:

     arecord -fS16_LE -r 22050 -Dplughw:1,0 - | sudo ./pifm - 100.1 22050
(pay attention to capitalization)

To do this of course you have to have a USB microphone, I have an old Wii Karaoke microphone that works just fine.  You can just pick one up off Amazon to, I just found a Guitar Hero one for about $15 here.

Step 4: Adding Other Songs

So you probably don't just want one song on your Raspberry Pi. To put the songs that you want onto it you have to have the correct format. It has to be a .wav file and if you have a .mp3 file or .mp4 or whatever, you need to convert it. You can use this online one here. It also has to be in 16 bit : 22050 Hz : mono. If it is not like that it will sound really slow and weird or really fast and weird.

UPDATE: There is now a way to use .mp3 files in your raspberry pi, here is a Google Doc for more information.
https://docs.google.com/document/d/1URn_9QpnP9CjUq9fpjuMdpL6svTr8hoGThmilHePV5g/edit?usp=sharing

To import your song just use an FTP server like Fillzilla, you can find a pretty good tutorial on it here. Make sure you import it to the home/pi directory (it is on it by default) to avoid extra work. As far as the code just replace the 'sound.wav' with the name of your song.

EX. sudo ./pifm livin_on_a_prayer.wav 100.1

If your song has spaces in it you may notice that it doesn't work, it will give you an error, to fix this put the name of the song in quotes.

EX. sudo ./pifm "living on a prayer.wav" 100.1

TIPS -
Make sure that you are capitalizing what you are suppose to
Be sure to spell everything right
You can see all of the songs that you downloaded by typing 'ls' in the command line
Any other questions, don't be afraid to leave a comment!

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Woodworking Contest

    Woodworking Contest
  • Make it Move Contest

    Make it Move Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

132 Comments

for those who have pi2 model b follow this persons vid on youtube. Works for me

https://www.youtube.com/watch?v=i5cp9R0SACg

3 replies

Thanks for sharing this video! I'll have to try it out sometime!

Just a question: I would like to use it in the car, because I have only built-in radio and cd player. I have a pi zero, can this run on it?
Thank!

can we use same code on rasberry pi 3 modal b.i reached on step 3rd but i have not recive any sonund on my handset so plese help me in code.

You do not want to be using this as a long term, stationary FM
transmitter. If any of your signals interfere with air traffic control,
emergency services (police, ambulance), etc they will come looking for
your signal and ultimately you. Looking at a spectrum analyzer with a
frequency of 88.7MHz there are harmonics all across the VHF band.
Centering on 121.5MHZ, your aviation band emergency frequency, there are
harmonics and intermod products all through aviation VHF band
(118-136MHz,) and VHF navaids (108-117MHz). If you use this you will
splash onto these frequencies. If nobody complains, nobody will come
looking for the signal. If this does interfere with aircraft, I
guarantee you someone, (FAA in US, Industry Canada in CA) will come by
with a DF and find you and you can be charged. Use with caution.

8 replies

Quite true, it generates a square wave and splatters all over the VHF and UHF bands. A frequency counter puts this at the specified freq above (100.1). Using a SDR with an antenna very close to the RPi I was able to see harmonics when the radio was active but not sending a wav file every 466Khz, granted, not a very accurate method but somewhat effective. While the radio was transmitting a Wav file I heard strong audio at 100.1, ~150, ~200, ~300(very strong), ~400(very strong), , ~600, ~700, ~900 and ~1.1Ghz. You can find some videos showing an actual spectrum analyzer how dirty this is as a FM radio.

The attached image shows some of the air band through the SDR while the Pi is not sending a wav audio. Also another image while transmitting at 100.1 showing it at 600Mhz

The output power is very low so it shouldn't be an issue, I can barely hear the radio 40ft away, just be aware of what @dleite says above.

Active-no-wav-air-band.jpgActive-Wav-transmitting-600Mhz.jpg

Hello,

Your comment is kind of a big deal.

Any idea how to filter this to get rid of the harmonics?

Can you do an instructable on how you found these spikes? I am not familiar with software defined radio (other than in theory) and would be a great way to detect dirty transmissions from homemade equipment.

Not sure we'd be able to get rid of the harmonics since they are being generated by the Pi. Maybe at the output (antenna) we could add a band pass filter before the signal gets to a tunned antenna so the range for the harmonics is limitted.

I might be able to do an instructable for this but I'll need to start from scratch since I keep configuring my Pi for different projects. SDR is easy to get started with using cheap dongles; you can find them anywhere from $10 - $25.

Adafruit has instructions on building a scanner using a Pi, don't know what it would look like but it's on my to-do list.

Hello,

What I am asking about, is what steps were taken to view the harmonics, and if you could make an instructable for this? (call this the "windsr method"). If I were designing a band pass filter, I would want to use this "windsr method" to make sure my filter works and I am not letting splatter escape and cause trouble.

user

haven't tested that yet, I live in a place where there should be no interference. I would like to hook this up to an rf amp and then a filter to deplete the interference. just using the raspberry pi and a length of wire shouldn't get you and farther than your house depending on where in the house the antenna is, and how long it is. I guess if I do cause harmful interference to aviation and others like that, it should be within my ham license limit. I would rather have my license stripped of me and have to re-take the test rather than be fined a couple hundred thousand dollars.

Still going to want to be careful. Interference in a non ham band such as the aviation bands have nothing to do with your ham license. Also, if you are in the US, if you have your license revoked it is much more difficult than just retesting to get it back. There is legal red tape and a very good possibility of not getting it back

Of course, this is just an example of how it could be done and people need to use it in complience with the FAA.

lol why worry? This puts out such a tiny amount of power a receiver will not pick it up less than 50 feet away. No DF is sensitive enough to pick up such a tiny signal. Heck even a large electric motor puts out more noise than this!

There is a new program up that I wrote where you only need the filename (NOT THE PATH). It will install everything for you, all you have to do is type in the frequency and the filename to be played (WAV or MP3, stereo or mono). github.com/CodyJHeiser/PiStation

2 replies

Glad to hear you are still working on this project! That is an excellent improvement

Thanks! I am working on a PiStation v3 now that would show recommended results. So if you typed in the song name wrong, instead of having to restart the program and type in the song name again it would say, did you mean 'this' song instead? But it is still in the development process!

I need your help as i searched but couldn't find what i am looking for

I'm using "rpi zero w" with 'recalbox' and i tried but it can't connect more than 1 usb device and its connected to HDMI Monitor (& monitors don't have speaker) ....... even bluetooth only works with gamepad and nothing else ......

I'm thinking to use "PIFM" to broadcast all the system sounds over to FM and use my Home Theater to play those sounds.

HELP ME BY GUIDING ME ON HOW TO ACHIEVE THAT AND HOW TO INSTALL IT ON RECALBOX as apt-get and other commands don't work on it

(using rpi zero w with recalbox 18.02.09)

The lesson here is that any electronic equipment that operates at high frequencies can become a radio, especially when you don't want it to be. it's called EMI Electromagnetic Interference. The trick is keeping your PC, switching power supply, TV, RPi from becoming a radio when you don't want it to be by proper cabling, filtering and shielding. I'm not sure about the details - I suppose there is some PWM going on. It would be interesting to find an actual FM SoC and mate it to the RPi to get a air-wave friendly transmitter.

Would this work on a pi zero?

I made this and it works great! But, the only concern I have is it possible to have almost like a playlist run? Or can you only play one track at a time.