TO BE CONTINUED
Notes on turning a Raspberry Pi into a portable FM radio transmitter with PiFm and Pi-FM-RDS.
Quick evening project : Raspberry Pi radio Long Term project : Raspberry Pi Radio
(article being redacted…). I wanted to do a quick project for a small evening but it turned out this project could become more interesting than I thought.
A bunch of people made a nice free-radio event this week-end in my town. That triggered some stuff I had in mind for quite a while : making a portable radio emitter
This project is about an FM radio transmitter. If you’re interested in making a webradio transmitter you can took a look at the Radiodan project.
This is not news nor a revolution but I wanted to document the process for myself (and probably others) and see what struggles I could encounter or, if any, improvements I could make.
I ended up using some excellent tutorials the www provided for me, for example instructables or makeuseof.
I didn’t write the code nor did I come up with the idea to use the raspberry Pi as a radio emitter. Before proceeding you should know that this could be illegal depending on which country you live in. Just so you know.
First I’ll set up the software using the traditional raspberry distribution (aka Raspbian). I wanted to try out the PiRadio OS provided by make, but it doesn’t seem functional with a Rasbperry 2B.
I’ll try using PiFm – the most straightforward one, I won’t go over PiFmPlay which is PiFm with some new features, like mp3 reading, playlists. But I’ll have a go at PiFm-RBS which has some neat station renaming features.
I’ll then improve the antenna (or more precisely, add an antenna) to broadcast at further ranges and then try some real time broadcasting using live-coding as an input and I’ll finish with some considerations about a portable broadcasting solution, with low-pass filter, battery, possibly a little LED screen and some control buttons. Ideally I’ll be able to switch between live-input, data from a usb device. I got some other ideas, but first let’s go with the basics.
1. Software
1.1 Setting up your Pi
Nothing special here, grab a raspberry Pi, put some SD card with a Raspbian distrib (or any other), plug-in the usbs and get some video output (or use ssh). There are loads on tutorial on setting up the raspberry Pi, so just google it. I used a Raspberry Pi 2 with the latest Raspbian jessie (2016-05-27) for this test. You can use another version as long as its more recent than August 2015.
- Add a
test wava test mp3 on the SD card, that’s something you won’t have to do later. (edit : apparently PiFm ships with a sample wav, so no need for that) - Grab Pifm : www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz you may want to untar it or do it later on the Raspberry Pi.
1.2. install the radio software
1.2.1. Using PiFm
So when Raspberry Pi is read, open a terminal, go to the folder you downloaded Pifm.tar.gz and untar it if not yet done (tar -xvf Pifm.tar.gz).
Start the radio by using :
sudo ./pifm sound.wav 100.1
Very simple command, you indicate the input file and the frequency you want to emit on. First try, first success here. No problem at all. Of course without an antenna the range is pretty limited but I could still hear the sound, even though it’s pretty noisy at about 5m from the Pi.
On it’s own PiFm doesn’t seem to have much more options. Let’s try to stream some mp3. I’m on debian Jessie, So I have to use avconv instead of ffmpeg. Install using with sudo apt-get install libav-tools.
avconv -i test.mp3 -f s16le -ar 22.05k -ac 1 - | sudo ./pifm 100 -
Avconv will read test.mp3 and pipe it to pifm which will broadcast on 100.0 Mhz. PiFm works pretty much flawlessly. Let’s check Pi-FM-RDS to get some more options.
1.2.2. Using Pi-FM-RDS
Pi-FM-RDS includes Radio Data System and can read wav and ogg.
I won’t go through all the steps as they’re explained here, so get sndfile library dependency, git clone, compile. If you switch from a raspberry 1 to 2, you have to compile again, using make clean.
sudo ./pi_fm_rds -audio sound.wav
This will emit on default frequency of 107.9 MHz. This will read wav or ogg but not mp3.
Example of a more advanced usage
sudo ./pi_fm_rds -pi 0x2A -ps LAUTRE -rt 'welcome' freq 107.9 -audio sound.wav
In this case, pi_fm_rds emits on 107.9. -pi is the station’s identification code, in hex. -ps is station’s name -rt is a radio text, max 64 char.
Piping works exaclty as in PiFm, for example, mp3 reading :
sox -t mp3 test.mp3 -t wav - | sudo ./pi_fm_rds -audio -
sudo arecord -fS16_LE -r 44100 -Dplughw:1,0 -c 2 - | sudo ./pi_fm_rds -audio -
References
- PiFmRds
- Make Magazine
- Radiodan : Using the Raspberry Pi to make a webradio
- Transmitting fm, am, ssb, sstv, fsq with just a Rasbperry Pi
Originally published on svdk.fr in 2016.