Выбрать главу

Regulation of the airwaves is necessary so the frequencies used by emergency services stay clear, but this transmitter uses only the public broadcast FM wave band. The worst that can happen is one of your neighbors receives your broadcast instead of their favorite radio station.

To build this radio transmitter, you’ll need the following parts:

ITEMS

NOTES

SOURCE

Raspberry Pi

Raspberry Pi 2, Model B or B+

Adafruit (2358), Fry’s (8258726)

Jumper wire

Female-to-female jumper wire

Adafruit (826)

Wire for the antenna

About 3 feet (1 m) of wire

Any wire will do for the transmitter; just check your box of scavenged hookup wire for something that will fit into the end of the female-to-female jumper wire.

You could add the radio transmitter to your existing Raspberry Pi setup. However, for maximum transmission range, you’ll want to put the transmitter somewhere high up, so I recommend getting a second Pi.

The length of the jumper wire doesn’t matter; it just allows an easy connection between the Raspberry Pi GPIO pin and the antenna wire. The wire to use for the rest of the antenna should be the right size to poke into one end of the female-to-female jumper wire and stay there. You might need to put a kink in the antenna wire so that it stays in place.

CONSTRUCTION

To build your transmitter, all you need to do is plug one end of the jumper wire onto GPIO pin 4 of the Raspberry Pi (Figure 10-2), then plug the antenna wire into the other end of the jumper wire and fix the other end of the antenna to a high spot so that the antenna is pulled up vertically.

Figure 10-2: Attaching the antenna

You will get the longest transmission range if you place the whole Raspberry Pi up high. If you have a watchtower, this would be ideal.

It does not matter if the antenna wire is not very straight. You may find that some electrical tape wrapped around the junction of the antenna wire and the jumper wire will prevent the antenna from becoming detached. Once you’ve strengthened the antenna, you’ve built your radio transmitter beacon!

SOFTWARE

I wish I could claim credit for the wonderful piece of software you’ll use in this project, but as it was developed by those clever folk at the Imperial College Robotics Society, I can’t. You can find out all about their project at http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter.

The software uses a sound file to oscillate GPIO pin 4 in just the right way to generate an FM carrier wave and signal (see the box on frequency modulation).

To install the software, start an LXTerminal session on your Raspberry Pi and type the following commands:

$ mkdir pifm

$ cd pifm

$ wget http://www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz

$ tar -xzf Pifm.tar.gz

These commands create a directory ready to install the software, download the software using the wget utility, and then uncompress the downloaded file into the newly created directory.

USING THE FM TRANSMITTER

To test out the FM transmitter, you need an FM receiver (see “Project 18: Arduino FM Radio Frequency Hopper” on page 188). You also need to find an unused frequency, or at least a frequency with only a faint signal. Of course, this won’t be a problem following the apocalypse, but it’s more of a challenge with the crowded preapocalypse airwaves. Use your FM receiver to find a quiet part of the spectrum and make a note of the frequency.

The software you installed includes a sound sample of the Star Wars theme for testing the transmitter before you record your own, more appropriate message—although the music is not completely inappropriate to accompany humanity’s great battle to save itself.

In the LXTerminal, issue the following command to play the tune over your transmitter:

$ sudo ./pifm sound.wav 103.0

In place of 103.0, substitute the frequency that your radio receiver is tuned to.

RECORDING A MESSAGE

To record a message, you’ll need a laptop and some sound-recording or editing software. I recommend Audacity, which is available free for Windows, OS X, and Linux from http://audacityteam.org/.

Fiction and history both tell us that when law and order disintegrate, bad behavior often follows. So think long and hard about what you want to say in your message. Who knows what gun-toting, supply-stealing outlaws are lurking around the corner? You’ll probably want to direct new arrivals somewhere you can observe them before lowering your defenses, so bear this in mind when recording your broadcast.

The pifm software requires you to record your message with the sample rate set at 16 bit 44.1kHz and then export the message as a WAV file. In the software, change sound.wav to the name of your new sound file, say my_message.wav.

FREQUENCY MODULATION

Frequency modulation, or FM as it is nearly always called, is a way of encoding a signal (in this case a low-frequency sound signal) on a much higher carrier frequency. The sound signal nudges the carrier frequency higher or lower than the carrier frequency, depending on the level of your message signal’s waveform.

Figure 10-3 shows two cycles of the message signal (solid line) superimposed on the much higher frequency carrier to create the broadcast signal (dotted line), whose frequency changes as your message signal changes.

Figure 10-3: Frequency modulation

When the signal is at its maximum, the peaks of the dotted broadcast signal are closest together. That means the frequency is higher than average. At the bottom of the waveform, when the signal has its minimum value, the broadcast signal peaks are farthest apart (the frequency is lower than average).

In this way, the low-frequency sound wave is encoded onto the high-frequency carrier wave. When this signal gets to an FM radio receiver, the circuitry in the receiver extracts the original low-frequency audio from the carrier signal.

RUNNING THE TRANSMITTER AUTOMATICALLY

To maximize the chance of other survivors discovering your message, repeat this broadcast around the clock. You can configure the Raspberry Pi to do this for you automatically using a Linux tool called crontab. The crontab utility lets you schedule programs to run at certain times of day.

Enter the following command into the LXTerminaclass="underline"

$ sudo crontab -e

This will open a configuration file with the nano editor, as shown in Figure 10-4.

Figure 10-4: scheduling your broadcasts

Scroll down to the end of the file and add the following line:

*/3 * * * * /home/pi/pifm/pifm /home/pi/pifm/sound.wav 101.0