Jam the airwaves with a Pi Zero

Our final project in this chapter is the ultimate in mischievous mayhem. We're going to use our Pi Zero to take over the airwaves by transmitting whatever audio we choose to a standard FM radio by using a rather nifty piece of software called PiFm. PiFm was originally written by Oliver Mattos and Oskar Weigl, and updated by a guy called Ryan Grassel.

The Pi Zero is perfect for this, because of its small size, and can be integrated with our wearable audio recorder built in Chapter 2 , Audio Antics, so you can interfere with FM radio reception out in the field.

Note

Very important: The laws for broadcasting FM signals—even over a short distance—vary from country to country. Ensure you check your local regulations before attempting this project.

In order to get range out of your radio jammer you'll need to solder a 20cm piece of wire to pin 4 of your Pi Zero's GPIO connector to act as an antenna. This should give a surprising range—perhaps up to 20 or 30 meters.

Tip

Compatibility Note: Owing to the way this software works, it's dependent on the operating clock speed of your Raspberry Pi. Having tested this, PiFm currently doesn't work on the Pi Model 2 or Pi Model 3 because they operate at a higher operating speed than it was originally designed for. Therefore, this project will only work with the Pi Zero and also earlier models such as the Model 1 B+ and B.

Installing PiFm

Let's get the code and compile it:

  1. Download the source code from the Git repository:
    pi@raspberrypi ~ $ sudo git clone https://github.com/rm-
        hull/pifm
    
  2. Change directories to pifm:
    pi@raspberrypi ~ $ cd pifm
    
  3. Compile the PiFm application with:
    pi@raspberrypi ~ $ sudo make
    

Broadcasting to the airwaves

Copy across a few of your favorite MP3 files to the Pi and put them in the default /home/pi/Music directory.

PiFm currently works only with 16-bit 22050 Hzfiles in the WAV format. But this is OK, as we can use the SoX sound exchange processor we installed in Chapter 2, Audio Antics, to take your MP3 file and convert it into the required WAV file on-the-fly and direct it to PiFm using the following command:

@raspberrypi ~ $ sox -t mp3 /home/pi/Music/somesong.mp3
    -t wav -r 22050 -c 1 - | sudo /home/pi/pifm/pifm - 88.5

Note

If you want to stash your mp3 files in a different directory, simply change the directory path that's underlined in the command above.

The above command works by converting the MP3 file into a WAV file using SoX, changing its audio sampling rate to 22050 Hz (-r 22050), and down-mixing the track to a single mono channel (-c 1). The converted track is then sent to the standard output, denoted by the hyphen sign (-) and is then piped (|) into the input of the pifm command.

Tip

Caution: Commands and filenames are case sensitive in Linux, so make sure you duplicate the exact capitalization of the previous commands (for example, the /Music folder name).

Now we have our favorite tune broadcasting, grab a radio and tune your dial to 88.5 MHz to listen to the audio output of your Pi Zero.

You can also do other clever things such as broadcasting your voice by piping the output of the arecord command, as we did in Chapter 2 , Audio Antics,to send to an audio device, or by using SoX to access a live Internet stream and broadcasting that over FM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.42.176