PiFM: A Pirate Radio with the Raspberry Pi

The popular single board computer, the Raspberry Pi (RBPi), can work as a radio transmitter as well. Using a simple hack, you can turn your RBPi into a powerful FM transmitter with adequate range to cover a bike parade, high school ball game, silent disco, DIY drive-in movie, or even your entire home. However, the broadcast frequency covered by the RBPi is rather large—one to 250 MHz, and there is a possibility this will interfere with government bands. Therefore, it is advisable to limit the transmissions to the standard FM band of 87.5 to 107.9 MHz.

You do not need much to make the RBPi start transmitting. The RBPi board itself, a power source, and the SD card with the OS is all that is necessary. The only accessory required is a piece of wire, which acts as the antenna. The entire project runs on the software PiFM.

Oscar Weigl and Oliver Matios developed PiFM originally, and Ryan Grassel revised it. This project uses the PirateRadio.py script, which enables playback without accessing the command line, while handling most common music file formats automatically. Wynter Woods, a MAKE labs engineering intern, wrote the script.

Oscar and Oliver had hacked the original PiFM code over a few hours. To output FM radio energy, their code used the hardware on the RBPi that actually generates spread-spectrum clock signals on the GPIO pins. Therefore, to turn the RBPi into a really powerful FM transmitter, all that was necessary was to add a wire length acting like an antenna to one of the GPIO pins. The original code used the GPIO pin 4 with a wire of length about 20 cm attached to it. For transmission, Oscar and Oliver had chosen the frequency of 100.0 MHz.

When Sam Freeman and Wynter Woods tested the present project, they found the FM signal only deteriorated once it had to pass through several conference rooms with heavy walls. The signal was able to cover 50 m easily, and objects such as heavy metal cabinets could stop it. They found the sound quality acceptable, although it has some clicks that came from the CPU switching to tasks other than playing music. For the technically minded, a kernel mode driver uses the DMA controller for preventing the RBPi CPU from being loaded, and thereby plays smooth music.

The Python script calls a C program that maps the peripheral bus of the physical memory into virtual address space. After this, it enables the clock generator module and sets points its output to GPIO4. Note that you will not be able to use any other GPIO pin at this time. It also sets the frequency of transmission to 100.0 MHz, which acts as the carrier. If you receive this on a radio, the radio will stop the background noise and become silent.

The carrier is modulated by the audio produced by adjusting the frequency using the fractional divider between 100.025 and 99.075 MHz. The fractional divider can produce audio with only 6-bit resolution. As the RBPi is very fast, it can use 128 subsamples on every real audio sample to produce 9.5-bit audio. The subsample algorithm now gives full 16-bit quality sound with FM pre-emphasis.