Skip to main content Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Raspberry Pi FM radio transmitter with Buttons

Published: 04-02-2015 | Author: Remy van Elst | Text only version of this article

Table of Contents

PiFM 1

The PiFM project allows you to use a Raspberry Pi to send out a WAV file onthe FM band.

This is awesome because every normal radio then can receive your music/podcastwithout expensive (sonos) equipment. It also allows you to listen in any carwithout the need for a radio that handles USB or Bluetooth.

I've used a lasercutter to craft a new top plate for my Pi which has roomfor three buttons. These are hooked up to a python script which allows me tostart and stop the transmission, and skip or go back songs. It also allows me toshut down the Pi instead of just pulling the power cable.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

Please do note that transmitting radio like this might be restricted in yourcountry. In The Netherlands this setup (on FM bands 87,5 to 108 MHz) forbiddenbecause it has too much transmission power. Transmitting on those frequencies isallowed if your transmittor has a maximum capacity of 50nW, and this setup hasway more than that. Source: Agentschap Telecom.


A small demo, shot with a phone and an Android app for lack of better equipment:

The Case

Short Crust

The base of my case is a Short Crust case for the Model B. I initiallybought this case because it reroutes the USB power to the front of the Pi. Imostly used it as a server back then, so having a power and a network cable atone side of the device is quite nice. The case also looks beautifull. I boughtmy case at Pi Supply.

Initially I wanted to use a 3D printer to make a case because I have someexperience with that. My hackerspace, Revspace has a Lasercutterand I'd never used that before.


I decided to replace the default top plate on the Short Crust with my own PMMAversion which should have place for the three buttons and easy access to theGPIO. I don't find a flat ribbon cable easy access. After receiving theinstructions and doing a few test cuts in plywood I fired up Inkscape and foundmyself a good ruler. I'd also never used Inkscape before but that is quite easyto figure out after some fiddling around.

The SVG file of the top case can be downloaded here. It was cut at power60% and speed 1.5. Below is a PNG version of the SVG:

Top Plate

My first attempts were not that great. Some measures were gambled the firsttime, as you can see in the below picture.


The holes for the screws were also a gamble, but, that was a lucky one, the arein exactly the correct spot. The button holes were measured up and since it arethree standard R13-57 buttons that was easy.

After two attempts and correct measurements I succeeded in printing the correcttop plate. It also has my website logo in it, the resistor symbol. That is justa nice touch.

The Buttons


I used three R13-57 push buttons for the input. They have wires soldered on tothem and a few pieces of electrical tape so that they do not short the Pi. Thereis little space in the case.

The buttons are wired up to GPIO pin 18, 23 and 24 (and ground of course). I'veused the built in Raspberry Pi Pull Up resistor. If you are using another boardof some kind please check if there is a pull up/down resistor built in,otherwise you need to place one in between the button and your GPIO pin, youwill get drifting otherwise.

PiFM 2

The Python Script

You can find the Python script in my github. It is inspired by the PirateRadio script frome Make Magazine.

The only part used from that script is the config and the ffmpeg to pifmconverting. That script has no concept of a global playlist so implementingstart, stop and skip functions in it would be harder.

I've used GPIO callbacks to handle the button input. The button functions arelisted below, where bottom is where the network and USB ports are:

If you first press the Middle (Stop) button and then the Top (Previous) buttonthe Raspberry Pi will shut itself down using the shutdown -h now command.After a few seconds you can safely disconnect the power of the Pi withoutcorrupting your SD card.

PiFM 3

Setup Instructions

[rasplayerfm] frequency = 101.0 shuffle = False repeat all = True stereoplayback = True music_dir = /rasplayerfm

When you boot the Pi up it will automatically start playing on the setfrequency. With the buttons you can start, stop and skip music as describedabove.

This was an interesting project for me because it upped my knowledge andexperience with a Lasercutter, Inkscape, GPIO, soldering and Python programmingwith callbacks and external inputs.

All the code (plus SVG file) from this article is released under the GPLv3. Theimages are Creative Commons BY-NC-SA.

Tags: articles, backup, debian, fm, ham, lasercutter, pifm, pirate-radio, pmma, raspberry-pi, revspace