loading

Here's the hassle free way to make your raspberry pi play your music files over FM-radio!

Skip to the next step if you are in a hurry ;)

For a couple of days I have been messing around with PiFM, and I absolutely love having my own radio station.
So far I've gotten about 50m range outside, not much, but certainly enough to broadcast at and around home. It is possible to improve the range drastically by adding filters and signal amplifiers , but broadcasting with that kind of range is illegal without a license -.-

Yup, pifm is awesome!!! But its a little impractical to use, you have to convert every different format and its troublesome to write the long one-liners over and over. It's just not practical to use if you're outside controlling it from your phone via ssh.

I wanted it to be as easy to use as the programs aplay and play, so I made PiFMPlay :D

PiFMPlay is here to make it easier to control your PiFM-radio broadcast.

I DIDN'T make PiFM! Kudos and thanks to icrobotics :D
http://www.icrobotics.co.uk/wiki/index.php/Turning...

I DID make the PiFMPlay script, and it's on github. Feel free to fork it from there: https://github.com/Mikael-Jakhelln/PiFMPlay

Now, lets get to it!

Step 1: Tl;dr (Too Long Didn't Read)

This is the quickest way to set up pifmplay.

Open a terminal on your Raspberry Pi.
Download pifmplay:

wget https://github.com/Mikael-Jakhelln/PiFMPlay/archive/master.zip

Unzip it:
unzip master.zip

Move the 'pifmplay' folder to /home/pi:

mv PiFMPlay-master/pifmplay ~/pifmplay

Go into the pifmplay folder:

cd ~/pifmplay

Then add execution permissions:

sudo chmod +x pifm pifmplay

Download & Install media converters:

sudo apt-get install ffmpeg sox libsox-fmt-all

Now edit you users bash config file:

nano ~/.bashrc

and type this at the bottom of the file:

export PATH=$PATH:~/pifmplay

restart the pi:

sudo reboot

Attach a 30cm wire to to GPIO4 (That's Pin-7)
Turn your FM-radio to frequency "91.3"

Start FM-Broadcast with:

pifmplay ~/pifmplay/starwars.wav 91.3

If you cannot hear anything on the radio, try adjusting your antenna

Step 2: Ingredients:

What you will need:
Hardware:
- A raspberry pi up and running with internet
- a way to type commands into you pi :P (ssh or a screen and a keyboard)
- a 30cm wire to use as antenna (any antenna/wire will do)
- a brain


Software(download links comes later in the instructable):
- pifm and pifmplay
- sox
- ffmpeg
- sound/music files

Step 3: Add Antenna to GPIO4

This one is easy:

- Connect your antenna (the 30 cm wire) to GPIO4 on your raspberry pi.

And that's all you have to with the hardware.

Step 4: Install Sound Converters

PiFMPlay uses sox and ffmpeg to automatically convert audio files and play them with pifm.

So to use it we need to install sox and ffmpeg. Type this into a terminal on your pi:

sudo apt-get install ffmpeg sox libsox-fmt-all

Step 5: Install PiFMPlay

Do this in a terminal on your pi:
go to your home directory:
cd ~/

download pifmplay from github
wget https://github.com/Mikael-Jakhelln/PiFMPlay/archive/master.zip

To unzip:
unzip pifmplay.zip

Move pifmplay to where you want it, e.g:
mv PiFMPlay-master/pifmplay /home/pi/pifmplay

remove empty folder:
rm -r PiFMPlay-master

Now go into the pifmplay folder, e.g:
cd /home/pi/pifmplay

change permissions so we can run it as a program:
sudo chmod +x pifm
sudo chmod +x pifmplay

Step 6: Change Default Frequency

change the default frequency in the pifmplay script.

cd ~/pifmplay
nano pifmplay

find this line, it should be at the top somewhere..
'frequency=91.3'
and change 91.3 to your preffered frequency

Step 7: PiFMPlay Is Ready for Your Orders, Now Play Some Music

Go into the pifmplay folder via a terminal, and type:
sudo sh pifmplay .
(this plays some music on the default frequency. Default is 91.3 if you didn't change it )

Now try:
sudo sh pifmplay "/path/to/folder/or/sound.file" 91.3
(change 91.3 to your desired broadcast frequency.)

Examples:
sudo sh $HOME/pifmplay/pifmplay "/home/pi/music/Daft Punk" 91.3
sudo sh /home/pi/pifmplay/pifmplay "/home/pi/music/Daft Punk/Daft Punk - Technologic.mp3" 91.3

Step 8: How to Use Pifmplay

Basically you just send what you want to play as the first parameter to the script, and the frequency to broadcast on as the second.
But read on, because there is more:

to play a file:
sudo sh $HOME/pifmplay/pifmplay "Name of - song.mp3"
to play a song on another frequency:
sudo sh $HOME/pifmplay/pifmplay "Name of - song.m4a" 91.3

To play a folder:
cd /into/the/folder/you/want/top/play
sudo sh $HOME/pifmplay/pifmplay .
or just
sudo sh $HOME/pifmplay/pifmplay "/path/to/music/folder" 91.3

to pause the broadcast:
sudo sh $HOME/pifmplay/pifmplay pause
to resume:
sudo sh $HOME/pifmplay/pifmplay resume
to stop:
sudo sh $HOME/pifmplay/pifmplay stop
to play the next file in the folder:
sudo sh $HOME/pifmplay/pifmplay next

If you want to run pifmplay in the background, type:
sudo sh pifmplay $HOME/pifmplay/pifmplay "/path/to/folder/or/file" &>/dev/null &


Now you are done installing pifmplay and you can enjoy using your fm-radio transmitter ;)

However; there's still some more ingredients you might want to add to your pie to make it even more awesome ;)

Step 9: (Optional)Now That PiFMPlay Is Up, Add More Music

To play music from a usb hdd or flashstick do this:

First things first:
Preheat the oven to 50°c, fold in a usb-drive into your pie, put the pie in the oven, let it cook for 50µs.
(DON'T PUT YOUR PI IT IN THE OVEN!!!! Just insert a usb drive into your pi)

Now you must find your usb media, so type in:

ls -l /dev/disk/by-uuid

That gives you a list of storage devices connected to the pi.
It should look like this:

pi@pi ~ $ ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 15 Jan 1 1970 676B-0317 -> ../../mmcblk0p5
lrwxrwxrwx 1 root root 10 Jan 1 1970 1B23-1234 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jan 1 1970 B321-4321 -> ../../sda2
lrwxrwxrwx 1 root root 15 Jan 1 1970 A1B2-3C4D -> ../../mmcblk0p1
/\ /\
this is the disk uuid & this is the drivename. remember these, we will use them later

Your usb media drive should be called something like /dev/sda1 or /dev/sdb1, where the number at the end is the partition number.
sda is the first drive while sdb is the second, the third and fourth drive would be sdc and sdd respectively
However, its NOT /dev/mmcblk0px, that is the sdcard your OS runs from.

Now, make up a name for your drive.
To mount your media, type:

sudo mkdir /media/yourmadeupname
sudo mount -t vfat /dev/harddrivename /media/yourmadeupname

(if your drive is not formatted as FAT16 or 32, you have to change "vfat" to something else)

To make it mount it automatically at boot, we need to edit /etc/fstab
make a backup of /etc/fstab with:

sudo cp /etc/fstab/ /etc/fstab.backup

edit /etc/fstab with:

nano /etc/fstab

Remember your uuid and your made up drivename?
Add this line the the end of the file:

UUID=youruuid /media/yourmadeupname vfat rw,defaults 0 0

Replace "youruuid" with your drives actual uuid, and "yourmadeupname" with the name you made up :P

If you didn't understand my instructions, or something was unclear check out:
http://www.techjawab.com/2013/06/how-to-setup-mount-auto-mount-usb-hard.html
or google it ;)

Step 10: (optional) Add Pifmplay to Your $PATH

If you want to type even less to play your music, you must add the pifmplay folder to your $PATH
This can be done in so many ways, and i'm not sure if this is the correct way. But it works :P

on your pie, type this:
nano ~/.bashrc

now type this into the bottom of the file
export PATH=$PATH:~/pifmplay

Source: http://stackoverflow.com/questions/8779951/how-do-i-run-a-shell-script-without-using-sh-or-bash-commands


now you should be able to type
sudo pifmplay "file/or/folder/to/play"
from anywhere, Yey! ¦-D

<p>is there any way to reveive fm using pi</p>
<p>does not work :(</p>
sudo apt-get install ffmpeg sox libsox-fmt-all<br><br>says &quot;E: Package 'ffmpeg' has no installation candidate&quot; :(<br>
<p>Hi, would this work on the pi 3?</p>
<p>Any way to use PiFm with MusicBox? Thanks!</p>
<p>Is there a way to play music from spotify? </p>
<p>I try to get ffmpeg but terminal returns:</p><p>&quot;Package ffmpeg is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, or is only available from another source</p><p>E: Package 'ffmpeg' has no installation candidate&quot;</p>
<p>not working for raspberry pie 2 unable to hear anything</p>
<p><a href="http://www.raspberrypi.org/forums/viewtopic.php?f=41&t=100381" rel="nofollow">http://www.raspberrypi.org/forums/viewtopic.php?f=...</a><br>you have to change some address in the pifm code so it works with the pi2, since it's a different processor ;) You might also want to check if icrobotics have updated pifm to work with the new pi2.</p>
<p>Do you have a backup of it?Topic got deleted...</p>
<p>nope sorry. if you find a fix, tell me and I'll add it to the repo on github :)</p>
<p>+Mickey_Boy Are you sure we need a brain for this project ???</p>
<p>Apparently :P</p>
<p>how to repeat songs in folder??</p>
<p>feature added by a collaborator on github just now, redownload from github and you will get the new feature.</p>
<p>can we use PI audio in to broadcast at a frequency. not play some stored files.</p>
<p>Read the instructable... pifmplay plays mp3s wavs and all sorts of other sound files.</p>
<p>Yes, you can set it to actually get audio from an audio device, and route it to the transmission. <a href="http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter#New.21_Now_with_stereo" rel="nofollow">The official page of this project explains how.</a></p>
<p>I precisely did what you said in the first step, yet there is an error message saying: /home/pi/pifmplay/pifmplay: 94: /home/pi/pifmplay/pifmplay: ffmpeg not found exiting. Please respond and answer. Seems great though!</p>
<p>ffmpeg not found means you do not have ffmpeg installed...</p>
<p>My transmitter starts transmitting a beeping sound when left on too long with no sound going to it. The USB soundcard keeps blinking when it does this while the LED stays static when it is functioning. What could be the problem? Does arecord reset the USB card at some point messing up the script? This is very frustrating as I am planning to make this a stationary transmitter.</p>
<p>Just started playing with a Raspberry Pi 2. Can't seem to get PiFM to work. It doesn't give an error, it just sits there until I cancel it. I don't get any output to a nearby radio. I've checked a lot of sites, including raspberry.org, but most of the comments are people arguing over the legality of it all.</p>
<p>http://www.raspberrypi.org/forums/viewtopic.php?f=41&amp;t=100381</p>
<p>That topic no longer exists, could you post the solution?</p>
<p>Awesome, thanks, that's exactly what I was looking for.</p>
<p>in my case its got started but i am unable to hear anything whats your status??</p>
<p>It's broadcasting, but not the wav file I send to it. I'm seeing people say that it's a trivial change, but apparently the questionable legality is preventing them from sharing. Too bad, I thought the point was to learn, not to be shielded from knowledge.</p>
<p>how to repeat songs i folder??</p>
<p>I am getting some strange problem ,When ever i try to play a song it play for a second and then it starts beep and keeps on beeping.....</p><p>I have tried everything changed power supply , changed antenna and reboot my pi several times .</p><p>Can you please help me?i need to do this as a school project sir :(.....</p>
<p>Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/liba/libav/libavcodec53_0.8.13-1+rpi1_armhf.deb 404 Not Found</p>
<p>Failed to fetch <a href="http://mirrordirector.raspbian.org/raspbian/pool/main/liba/libav/libavcodec53_0.8.13-1+rpi1_armhf.deb" rel="nofollow"> http://mirrordirector.raspbian.org/raspbian/pool/...</a> 404 Not Found</p><p>how to sloved this error</p>
<p>Is it possible to put a text on the display of your radio? For example I play a song, and you can see on the radio which song it is.</p>
Both sox and ffmpeg should display the song in the terminal on program execution.
<p>also,(i am not good with coding) as a recommendation in the future i would add a shuffle command so people can restart their stations and hear different music than before, Thank you so muchfor your work on this. i loved pifm before but now it is sooooo much easier to use!</p>
<p>That's a good idea. But right now I'm busy playing with other things. Feel free to add features to pifmplay on github.com</p>
<p>Hi, thanks for the instructable. Do you know if there is a way to change the frequency of the transmission while the song is playing? I.e. Without having to stop it and then replay it? Thanks!</p>
<p>Not atm. Feel free to add features on github.com ;)</p>
<p>hi, i would want to know, how i can use the function playstream with Spotify?</p>
<p>I guess something like this: <a href="https://www.npmjs.com/package/libspotify" rel="nofollow">https://www.npmjs.com/package/libspotify</a> could work. But I have no plans on expanding pifmplay, I'm busy playing with other things ;)</p>
<p>sudo mount -t vfat /dev/harddrivename</p><p>&quot;harddrivename&quot;?</p><p>which one is that? </p>
<p>that depends, unplug you hdd and open a terminal.<br><br>'cd /dev/'</p><p>'ls'</p><p>you should now see a list of devices and their respective names.<br>usb hdd and memory sticks comes up as sda, sdb, sdc, sdd and so on<br></p><p><br>plug in the hdd<br>'ls'<br><br>then look for the new drivename if you only have one drive connected, it should be /dev/sda, drive partitions appear as /dev/sda1 /dev/sda2<br><br>if your drive is called /dev/sda, and it is formatted with fat32, then write<br>sudo mount -t vfat /dev/sda<br><br>if your drive is not fat32, change 'vfat' to correct format.<br><br></p>
<p>one quick question, Will pifm play look into the folders in a folder and play the music in their. I currently have it so all the music files (more than 7 hours worth) are in one folder, but my brothers/ mom have different music preferences and i want to be able to have it play all music if i choose the parent folder, but have the music in the specific folder for the person in my family. Does all this make any sense? sorry if it is a bit comfusing</p>
<p>mp3 songs playing slower than it suppose to be</p>
<p>Try using (or borrowing) one of those $5 USB Sound Card thingys.</p><p>Basically the sound-out on the Pi is very bad... pops and clicks if the Pi is doing anything else. (The new Pi B+ model has improved power filtering which helps with this issue, but an external USB sound device will give best results).</p>
<p>can here music just a blank noise</p><p>PLZ help??</p><p>ps. this works as a jammer</p>
<p>plus it saing not found exiting</p>
<p>On mySD card is fresh installation of Pifm, installed using the steps mentioned in this guide:</p><p><a href="http://makezine.com/projects/make-38-cameras-and-av/raspberry-pirate-radio/" rel="nofollow">http://makezine.com/projects/make-38-cameras-and-a...</a><br><br>When i type commands (everything apart from the basics: halt, reboot, cd, pwd, ls...) the Rasbpberry PI doesn't do what it's told to... That effectively leaves me stuck on the first step in this tutorial!<br><br>Example of the type of messages i receive:<br>I typed:<br>apt-get install ffmpeg <br>-bash: sudo: command not found<br><br>Since I am trying to install PiFMPlay, any answer helping me further along doing so would be much appreciated!</p><p>-Jlynggaard<br><br><br></p>
<p>Hmm, sounds like you made a mistake somewhere when installing PiRateRadio. Probably a fault in a config file that keeps your pi from booting properly, thats why it cant find the sudo program.<br>If i were you I would re-flash the sd-card, and start from a fresh raspbian install -_-</p>
<p>But if i first install Raspbian using Noobs, and then install the PiFM image using Win32Diskmanager, won't i be overriding something? </p>

About This Instructable

92,541views

100favorites

License:

Bio: Not much to say. I'm a student, learning about computers, and I like to tinker with electronics, 3D-Designing, prototyping and machining
More by Mickey_Boy:Raspberry Pi - PiFMPlay - FM-Broadcasting Simplified Raspberry pi - simple 2x2x2 led cube 
Add instructable to: