Using a Raspberry Pi to Transmit to the 2 Meter Ham Band
I was recently inspired to experiment with some simple circuits using the Raspberry Pi 3B+ GPIO. I began by following the directions in the chapter “Using the GPIO Pins on the Raspberry Pi” in the book Adventures in Raspberry Pi to breadboard a circuit to light an LED by pressing a button.
While searching the web for a design to build an oscillator, I learned an interesting fact about the Pi: the board has a Spread-spectrum clock controller that operates on the frequency range 1MHz to 250MHz, which is in the VHF range typically used for FM radio.
Full disclosure: I am doubtful of a practical application for this and it is intended just for fun and novelty. I’m unsure of the power of the transmission, but the Pi itself runs on a 5V power supply. The range is limited since I’m using a short jumper wire as an antenna. This project allowed me to experiment with RF on the Pi quickly and easily with materials I had on hand.
I found the article How to Build a Raspberry Pi FM Transmitter which is geared toward playing music audio files on a wideband FM frequency. The article links to the original project which is documented in the post Turning the Raspberry Pi Into an FM Transmitter. Originally, I tried to follow the latter because it is more explicit about the technical details. I also appreciated that it uses a Python script because I could read the code and try to make sense of what it was doing. However, I ran into problems because it calls a precompiled C binary that would not run on my 64-bit Raspberry Pi OS, despite my efforts.
I cloned down the fm_transmitter repo linked in How to Build a Raspberry Pi FM Transmitter, which contains a C program that properly compiled on the Pi using the directions.
sudo apt-get install gcc g++ make
cd fm_transmitter
sudo make
I copied a .wav file of a recording of me keying my amateur radio callsign on a practice oscillator onto the Pi using a thumb drive.
I prepped the Pi by putting on my Adafruit reference card overlay on the GPIO and connecting a jumper cable to pin 4 (4th down on the right.)
Since I’m a licensed amateur radio operator, I’m permitted to transmit on the 2 meter band, which falls in the range supported by the clock controller and the program. I set the program to use the 2 meter simplex frequency.
sudo ./fm_transmitter -f 146.52 -r kb1hfp_call.wav
The linked video shows a demo of the program where I transmit a file containing a recording of my callsign in morse code using the Pi Spread-spectrum clock.
Why is sudo
needed? Why is GPIO pin 4 used? Turning the Raspberry Pi Into an FM Transmitter explains: “The C program maps the Peripheral Bus (0x20000000) in physical memory into virtual address space using /dev/mem and mmap. To do this it needs root access, hence the sudo
. Next it sets the clock generator module to enabled and sets it to output on GPIO4 (no other accessible pins can be used).”
I have not yet been able to determine why the pitch of my tone is so much lower and slower than the sound on the original file.
I tried to dig into how this works and got out of my depth very quickly reading the Stack Exchange post How does the RaspberryPi radio hack convert digital GPIO signals to an FM signal? There is a lot of interesting information, many explanations, and diagrams in the post.
The experiment was relatively quick to set up and it was fun to test out the proof of concept for an interesting hack.
73,
Jamie, KB1HFP