Hardware Reference
In-Depth Information
Tune a radio to 103.3 FM and put it near your Pi. Then open a terminal and enter:
$ sudo python
>> import PiFM
>> PiFm.play_sound("sound.wav")
If you want to play your own sound, convert it to WAV format (16 bit mono, 22 Khz is
best) and put it in your home directory.
This will work only with the radio next to the Raspberry Pi. To get a little more range,
you can connect any 50 cm wire to GPIO4 to act as an antenna. Pointing it straight up
works well and should get you around 50 m of range.
You might need a license to transmit radio in some countries, so if you're unsure,
it is best to leave the antenna disconnected. It will still work, but with a very short
range.
Compile the code for pifm.c using the following command:
$ gcc -lm -std=c99 pifm.c -o mypifm
To broadcast your WAV file, just run:
$ ./mypifm myaudio.wav
How It Works
FM stands for frequency modulation , which is how it sends sounds over the air. Fre-
quency modulation works by having a signal (called a carrier signal ) that regularly
changes from positive to negative and back again very quickly (in the case of the PiFM
radio, it changes and changes back again 103.3 million times every second!). When
you vary speed of this change to be just a bit faster or slower, the radio on the other
end can detect the changing speed and makes sound based on how it changes.
But how do you make the Raspberry Pi change something so quickly and accurately?
The Pi has an on-board clock manager that can accurately produce any clock fre-
quency you want by dividing the system processor clock (which is normally around
500 Mhz) down to any other rate you want. To tell it what to do, you set a register (a
special piece of memory) to a number saying what you want the system clock divided
by to make the FM radio clock. For example:
• System Clock = 500 Mhz
• Divider Register = 5.000
• FM radio clock frequency = 500/5 = 100 Mhz
 
Search WWH ::




Custom Search