FM Radio Station With Raspberry Pi
If you have an extra Raspberry Pi lying around and have always wanted to fill the airwaves with that special mixtape you made for your high-school crush, this is the project for you.
Required Skills
- Linux
- Git
- Familiarity with Raspberry Pi
- Windows
- Tiny bit of programming experience, but really just the ability to edit a text file precisely.
What you’ll need:
- Raspberry Pi (I’ll be using a Raspi Zero)
- SD Card with at least 6GB of storage
- SD Card reader
- ~15cm of wire (Solid core 20ga)
- Soldering Iron
- .8mm Solder (2% flux)
- USB/USB-C to MicroUSB cable
- TV Tuner Dongle with Antenna (Just throw out the Software CD that comes with it)
- Windows capable computer (unfortunately)
Part 1. Preparing the Pi
Before we begin, you will need to flash your Pi’s SD card with a new version of Raspberry Pi OS, available for download here: https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-32-bit
If you aren’t familiar with the process of flashing SD cards with Disk Images, then all you need to know is that we are wiping the SD card of all the existing information, and uploading a new operating system on to it. When the chip is inserted into the Raspi and it is plugged in, the Raspi will automatically check the chip for the operating system it needs to boot(start up).
Personally, I like using the Balena Etcher to flash my SD cards with new images. They also have a bulk flasher, in case you are wanting to flash more than one at a time, or have some bulk mischief planned.
Side note: Balena also has a bunch of fun projects that let you turn Raspberry Pi’s into all sorts of useful gadgets. I have one that upgraded my analog surround sound speakers into bluetooth speakers.
Setup Steps:
- Download the aforementioned OS and flash it on to your SD card.
- To enable shell access from your computer, you will need to modify some of the files in the SD card. This link does a good job of explaining the ssh setup. Basically you just need to add
dtoverlay=dwc2
to the end of the /boot/config.txt file, add a blank file named “ssh”, and edit the cmdline.txt to look like so:console=serial0,115200 console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh
- When this is saved, you can eject the card and insert it in your Pi. Now you can jump in Terminal and type:
sudo ssh pi@raspberrypi.local
which should bring you to the login for the Pi. The default user and password for Raspberry Pi’s is:
user: pi
password: raspberry - Time to connect your pi to the internet. The command to access the prompt for the config is:
sudo raspi-config
… crazy, I know. From these settings, connect to wifi using the WLAN (wifi). Also, change that password while you are at it.
5. Now set the time zone to match your computer’s. Forgetting to do this will seriously ruin your day, as you’ll be troubleshooting for hours with no results.
Tip: you will want to update your Raspi, even though you just flashed it. Here is that command:
sudo apt-get update && sudo apt-get upgrade -y
6. Create a directory in the /home directory called “radio” and cd into it:
mkdir radio && cd radio
7. Next you will need to download this repository into your “radio” directory with the following command:
wget https://github.com/markondej/fm_transmitter/archive/refs/heads/master.zip
8. Install the required dependencies:
sudo apt-get install make build-essential
9. Move into the fm_transmitter directory and use the “make” command
cd fr_transmitter && make
10. If you did everything correctly, you should be able to test the transmitter with the audio file provided in the repo:
sudo ./fm_transmitter -f 102.0 acoustic_guitar_duet.wav
From the above command, I think its pretty clear how this program works. Drop an audio file in there, specify the freq you want to broadcast on, and hit enter. There are most specific instructions for how to get detailed with it on the repository README.
I know what you’re thinking: “Great! Now… how do I listen to it?” What, you don’t have an analog radio lying around?! Me neither. This is why the TV Tuner is in the parts list. This unsuspecting gizmo will allow us to visualize all of the frequencies, and tune into our little pirate radio. Time to set this badboy up.
Part 2. Setting Up the Tuner
Right out of the box you will probably thing to yourself: “Welp… this shit is sketchy.”
That’s because it is.
Let’s get started. =]
For this next part you will either need a Windows computer, or an emulator capable of running windows on your machine. If you don’t have that available to you, I recommend getting a $10 analog radio from Walmart or something.
If you’re really wanting to partition your HD on your Mac computer and try to run windows on it, check out Parallels. It’s a software that does the heavy lifting for you.
- Download the program HDSDR. You probably saw this retro-looking program in the beginning of the article. It is from this sketchy german website: www.hdsdr.de The license agreement is in German but… Germans are super, super trustworthy, so I just clicked accept.
- After you install it on your machine, make sure you follow the instructions here: http://hdsdr.de/RTLSDR_with_HDSDR.pdf
Basically, these instructions tell you to NOT install the real driver for the TV tuner, but use a program called “Zadig” to install a different driver that enables it to act as an FM radio receiver. You will also install an auxiliary file that tricks the HDSDR program into thinking the TV Tuner is the FM radio of the computer (which is kinda actually is now). - You can now open up HDSDR. Right off the bat you should be able to press the green “play” button and start scanning radiowaves. Notice that I am set to “FM” instead of “USB”. The little hack we did with that aux file makes this the default.
Getting to know HDSDR
Notice the broadcast on this frequency below. See how there is a red line indicating the freq we are currently tuned to? The light-blue box around it indicate the bandwidth of the tuner. This can be adjusted to allow more, or less of the surrounding frequencies through. In this example, the signal is relatively localized, but let’s look at an actual radio station.
Here is an example of a larger broadcast:
Instead of a spike, larger radio stations will have a larger bandwidth that allows them to send higher quality audio. You can adjust the bandwidth of your program to take in more, or less of it to suit your needs. If you’re hearing a station but it’s static covered, this will be a good place to start your troubleshooting.
To adjust the bandwidth, select the “bandwidth” option on the lower left-hand menu. This window should pop up:
You can mess around with the settings in here, but the program actually auto-selects what it thinks the best settings are, so you just close this window out, and a litter slider will appear to the right of it. See below:
This slider is a much more user-friendly way to interact with the bandwidth option, and you can watch the cursor and bandwidth box react in real-time.
Testing Everything
Earlier in this tutorial I gave you a command to test out your radio. Let’s use that now with HDSDR tuned to 102.0MHz:
sudo ./fm_transmitter -f 102.0 acoustic_guitar_duet.wav
When the Pi runs this program, you should see an FM broadcast begin at 102.000.000. The screenshot below shows a time chart of the relative silence before the broadcast starts, and then the station and ripple stations once I ran the command.
The top box is the signals over time, directly under that is the current signals. The bottom right boxes are a spectral analyzer, and a band filter modifier. The bottom left is the HUD we were talking about with various settings.
To list some, we have:
- NR: Noise Reduction (Static Reduction)
- NB RF: RF Noise Blanker (Radio Freq. Noise Reduction)
- NB IF: IF Noise Blanker (Impact Freq. Noise Blanker) ← these are commonly caused by ignition events, or something being removed quicky. Its a spike of EMF that can really hurt your ears if you have your headset cranked to 11. You’ve probably heard this when someone plugs in a speaker at a concert. ZEEEAAP!
- AFC: Automatic Frequency Control: This setting tries to keep your tune on the strongest part of the signal. I get why they made it, but I prefer not to use it.
- AFG: Automatic Gain Control: Gain is a pretty confusing topic, mainly because it generally is talking about the same thing around a couple different fields of science, but also… not. In radios, gain refers to power gain. Wikipedia defines power gain as such:
The power gain of an electrical network is the ratio of an output power to an input power. Unlike other signal gains, such as voltage and current gain, “power gain” may be ambiguous as the meaning of terms “input power” and “output power” is not always clear.
- … right. I just leave it off.
- Notch: This is a type of filter called a (you guessed it) “Notch Filter”. If you are experiencing signal deprecation from a specific frequency, a notch filter can help you cut it out.
- ANotch: Automatic Notch.
In that “Options” menu you can find all sorts of customizations and more settings to mess around with.
Wrapping things up
OK SO! We made a little FM radio station, we turned our old PC into a frequency scanner and temporarily got sucked into the world of the electromagnetic spectrum and radios (ugh, I love them so much). Is there anything we can’t do? Probably not.
By this time, you’re probably thinking about all the possibilities for this fun little Raspberry Pi, and I have to admit, they are pretty endearing.
I had lot’s of fun making this project with you guys, and I even found some new radio stations in the area that led me to this song, so let’s let this be the anthem of the lesson, and come back next time for some other kooky project!
https://open.spotify.com/track/4M4lJsxDlVDeeecdhqArDe?si=445ac0c555634862
Safety Notes:
- Make sure you dont accidentally use the Zadig program on your keyboard or something, it will wipe the driver.
- Don’t forget that soldering iron you left plugged in. Pets and carpet are flammable.
- If you get strange emails from germans, don’t answer them.