/pi-gpioradio

A simple script for FM radio transmission using a Raspberry Pi and its GPIO pins

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Pi-GPIORadio

A python script for triggering the transmission of music and microphone input via FM radio using the GPIO pins on the Raspberry Pi

IMG02353_adjusted-small

How it works

The script checks for input on three different GPIO pins and executes the according command if one of them is connected to ground. The command is issued inside a screen session so that the transmission can be stopped conveniently. If you connect the so called "terminatior" pin to ground, the screen session will be killed and the transmission will stop. The pin assignment and the overall procedure is of course customizable. It supports:

  • Transmission of audio files (in this case .mp3s)
  • Transmission of microphone input (USB microphone)
  • Control via GPIO pins

Default GPIO pin assignment

gpio_default

GPIO.21 - Music transmission

GPIO.20 - Microphone input transmission

GPIO.26 - Terminator (Stop transmission)

Prerequisites/Dependencies

In order for this script to work you'll want to have Python, ffmpeg, screen & git installed on your system. Python is included in Raspberry Pi OS so you'll only have to install the ffmpeg, screen & git packages. Do so by issuing the following command in a terminal on your Pi:

sudo apt update && sudo apt install ffmpeg screen git

Confirm by typing "y" and pressing enter if asked for confirmation.

You will also have to download the "pifm" package by "omattos" which is described in the Instructions section down below.

For better transmission range you can connect/solder a wire to Pin 8 (GPIO4) on the Pi. If you happen to have a broken radio lying around, you could salvage the antenna and mount it onto your Pi like I did with my Zero W.

Note: ffmpeg is needed for transmission of .mp3 files because pifm only supports .wav files by default.

Instructions

  1. Clone this repository
git clone https://github.com/nohouse-felix/pi-gpioradio.git
  1. Change directory to the "pi-gpioradio" folder
$ cd pi-gpioradio
  1. Download the "pifm" package
wget https://omattos.com/pifm.tar.gz

Shoutout to Oliver Mattos & Oskar Weigl for the PiFM script/software!

  1. Extract the package
tar -xzvf pifm.tar.gz
  1. Verify the new files by typing
ls -la
  1. Modify the "pi-gpioradio" script if you wish to change the GPIO pins or something else
nano script.py

IMPORTANT: The script assumes that you are using the default "pi" user.

Be sure to modify the directory paths in the script if you use a different user account!

Simply change the numbers of the GPIO pins to different ones if you wish to use different pins. If you want to you can set a different FM frequency. The default one is 99.8. You can also alter the directory in which the script looks for .mp3 files.

  1. Connect a wire or an antenna to Pin 8 (GPIO4) on your Raspberry Pi for better transmission range.

gpio4

  1. Populate the "pi-gpioradio" folder with .mp3 files

Make sure to copy your songs and recordings over to the "pi-gpioradio" folder. You can also specify a different path in the script and use that for storing your music.

  1. Make the "pi-gpioradio" script execute at boot
sudo nano /etc/rc.local

One line above the one that says "exit 0", insert the following:

python /home/pi/pi-gpioradio/script.py

Note: Be sure to change this if you don't use the default "pi" user!

  1. Reboot

  2. Done!

Grab a wire or something else suitable to connect the pins and give it a test. Be sure to terminate the transmission before you switch from music to microphone transmission or the other way around! Make sure to tune your receiving device to the correct frequency. If you didn't change it, it's 99.8

Please note: Transmitting signals over the FM band without federal permission or authorization is very likely to be illegal, depending on which country you're in. Use at your own risk.