Pi Zero FM Radio
Similar to my story about the SanDisk Connect device, this idea started it’s roots in my trip to DefCon 2018, specifically my experience in the Wireless CTF. I wanted to recreate some of the RF signals I was able to “hear” using my gear. I could hear quite a bit but had no idea what to do with it. There were quite a few people running the CTF, they were all over the room. The issue was my pride not simply wanting to reach out and admit what I am: a pleb.
So when coming back to my desk at home, I took my notes and started to research methods to transmit the similar items that I had heard and what was covered on the debrief. My HackRF was still on the way from Amazon but I was eager to get to work. I believe I initially started researching Raspberry Pirate Radio as found here. This seemed a little more than I was going to start with since I really hadn’t played with any of the Raspberry Pi models at that point. In a flurry of googling and reading, I landed on this article, also by Makezine.
I didn’t make a throw-able as I wasn’t going to simply do as the article suggested and take a bare Pi Zero and attach a battery with some magnets and toss it up somewhere. What I wanted to do is transmit in the FM band on the cheap at an extremely short distance. I couldn’t pinpoint the exact stance of the FCC. A website stated the FCC wants a FCC ID on any transmitter, such as one you might pickup to broadcast your smartphone, or back the day, a diskman to your automobile radio. Reading §15.239 of Part 15 of subchapter A of Chapter A of Title 47 wasn’t too clear.
Here’s what I did understand as a licensed ham, it’s my responsibility to understand what I was doing and if I start interfering with normal FM transmissions as well as impacting users around me, to knock it off. So I gathered the materials at my local Microcenter and came home to get this party started.
I started the project just as described in the article.
- Solder the wire antenna.
- Download and Install Raspbian.
- Boot the Pi Zero.
- Install PiFM and MPG123.
- Run PiFM.
The install of PiFM and MPG123 is straight forward for someone with experience downloading and installing from either apt or cloning from github.
MPG123:
sudo apt install mpg123
PiFM:
git clone https://github.com/rm-hull/pifm
To run pifm with the mp3 of my choice, execute the following in the terminal:
sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/lincoln.mp3 | sudo /home/pi/PiFM/pifm/pifm - 88.5
Now the lincoln.mp3 is an interesting thing. Shortwave is something I always have found fascinating but haven’t explored. On the hunt for some mp3 files for some number stations, I came across http://priyom.org as well as http://users.telenet.be/d.rijmenants/. Just a short wget away from downloading the file to my Pi.
Oddly enough my selection of FM radios around the house is pretty slim. I wasn’t about to pull the radio of the shelf in the garage to listen to the transmission in the house. Since I have a few RTL-SDR dongles, why not use them. The surprising finding was the transmission or spurious emission that the Pi Zero didn’t stop with a ctrl-c. I had to restart the blasted thing to get the Pi to stop.
This was concerning. I wanted to tinker and transmit but also I’m trying to operate the the realm of being a responsible adult. Although if you are transmitting and then shut it off, then the impact might not be as great. I wasn’t too keen on the idea that you stop the program but the Pi continued to transmit dead air. I went back to researching aka google. I came across this github: https://github.com/markondej/fm_transmitter. Taking a look at the readme, I knew this was well within my wheelhouse to give a go.
mkdir FM_Transmitter
git clone https://github.com/markondej/fm_transmitter
Following the directions and some testing I resulted in this command:
sudo fm_transmitter/fm_transmitter -f 88.5 -r fm_transmitter/star_wars.wav
I mean it was totally worth a shot when there’s a star wars wav file in the repository. Sure enough, on the FFT plot and waterfall of gqrx, the wav file was being transmitted. When I used ctrl-c to stop, the transmission stopped.
The one thing I noticed was the limitation to wav files. Not that I did much research beyond getting the fm_transmitter to just play the default star wars file. I started to think about another idea I had. If I wanted to transmit Morse code, since I could hear it but not decode it in the desert, I had already found a website that will pump out an mp3 of Morse code. Back to googling.
What I came up with was the following software and process to convert a mp3 file to a wav file on the Pi Zero. Install ffmpeg and sox. Then using those, execute the following on the mp3 of your choosing:
ffmpeg -i lincoln.mp3 lincoln.wav
sox --ignore-length lincoln.wav lincoln2.wav
There’s an error which I can’t recall exactly that when you take the file directly from the ffmpeg conversion to fm_transmitter that it complains about the file being 0 length or empty. Using sox will tidy things up.
So was it worth it? It depends. Relatively inexpensive compared to a regular Pi. I forget what I paid for the case and the SD card but the Pi Zero W was $5. A little experimentation is good for the tinkerer. It was interesting to hook up different RTL-SDR dongles and listen. It’s not a clear signal on any RTL-SDR dongle that I have. Even the Baofeng can’t get it to come in clearly. There goes my idea of having a Pi Zero as a Morse code transmitter. The trip was worth the cost though. A opportunity to learn something new. Research how to turn mp3s into wav files. I did use the Pi Zero using a camera to broadcast the image out the internet.
Thank you for reading, hopefully you’ve learned something. Twitter: @grnbeltwarrior Github: https://github.com/grnbeltwarrior