Courtesy of RyanB27 over at Instructables today we show you how to exploit the fact that the Raspberry Pi supports AirPlay (through shairport), and combine it with the ‘hack’ that allows the Raspberry Pi to transmit FM signals, turning your raspberry pi into a dedicated AirPlay server and FM transmitter.
Here is the best part, the requirements:
1x Raspberry Pi (any model except Pi 2)
1x Long wire (preferably around 2 feet in length)
1x FM radio (many speaker systems and nice alarm clocks have a built in FM radio).
Original build instructions here.
Hook up a wire to GPIO 4. This is the fourth pin down on the left side. The wire can be up to 30 inches long.
My assumptions is that you have setup your raspberry pi before. You can either SSH into it, or just do it with a monitor, mouse, and keyboard. For optimal performance from Airplay, I suggest having the Pi hooked up to the network with an Ethernet cord and the Pi not overclocked (this will mess with the FM radio if it is overclocked).
After you login to your raspberry pi, at a terminal window install PiFM:
tar -xvf Pifm.tar.gz
1. Makes a director named pifm
2. Makes the “Current Directory” pifm
3. ‘Gets’ the file at the link provided.
4. Essentially unzips this file.
FiFo stands for First-in First-out. This will act as a buffer, we are going to send music to this file, and as the music gets into the file it will be read by the PiFM program we just setup.
sudo mkfifo fmfifo
This will make a fifo file. That’s all for this step.
Side note: For those more familiar, a higher performance option is to make a fifo in a tempfs folder, but this file will get lost after reboot. I would enjoy suggestions to improve this. This isn’t necessary for now though.
Lets install shairport. This allows the Pi to act as a AirPlay Server, and receive music from our AirPlay compatible devices.
First, we need to update our raspberry pi. This will take up to 10 minutes.
sudo apt-get update
sudo apt-get upgrade
Lets now install all the necessary files for airplay:
sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl
Let us install a depedency.
git clone https://github.com/njh/perl-net-sdp.git
sudo ./Build test
sudo ./Build install
Let’s instal the final files
git clone https://github.com/hendrikw82/shairport.git
sudo make install
This will install shairport.
Side note: There are newer versions of shairport, there are a variety of branches. It is hard to choose the best one but this one works, which is all I require. I recommend people taking a peak at shairport-sync if they want to use multiple raspberry Pi’s instead of a central fm transmitting one (you’ll get better audio quality with shairplay sync, but it costs more).
Lets do the final steps! You may need to have two terminal windows open, one for each command as they tend to ‘take over’ the window.
sudo ./shairport/shairport -a "NameOfServer" -o pipe /fmfifo
sudo ./pifm/pifm fmfifo 107.9 96000 2
The first step creates a server, which you can change the name of. The name is what you see when you connect with your compatible device.
The next step sets the frequency. I have it set to 107.9, but use an empty radio station in your area. After you run both steps, tell your iOS device to play music to “NameOfServer” and you should hear the music on the radio station you chose.
Side note: A sample rate of 96000 should work for current devices. If the music sounds too high pitched or too low/slow, you may need to change the sample rate. In this example, I was streaming from my phone on iOS 8. In the past I use to use a sample rate of 44100, but for whatever reason I had to use 96000 this time. If the music sound slow, use a higher number. If it is too fast, use a lower number. Sampling rates are commonly one of the following rates: 96000, 88200, 48000, 44100, and 32000. You’ll probably use 96000 or 44100 for most systems, I think it is an Airplay/iOS version related number.
You’ll have to run the last two commands every time you reboot to start the radio again.
The raspberry Pi FM transmitter is very noisy and does not follow regulations, which is why I never looked at a method to start automatically. Use it sparingly. Don’t use it around airports. Only use it when you need to, and make sure the station goes back to static when you are done.
Tags: raspberry pi
The scorching South African heat can really take a toll…
Amaze your friends with this easy to make an cool…
YouTube content creator wermy (no real name given) has produced a work…