FM Transmitter

Using Raspberry Pi as FM transmitter

It uses the hardware on the raspberry pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM Radio energy. This means that all you need to do to turn the Raspberry-Pi into a (ridiculously powerful) FM Transmitter is to plug in a wire as the antenna (as little as 20cm will do) into GPIO pin 4 and run the code posted below. It transmits on 100.0 MHz.

Steps to play sound:

Connect a 20cm or so plain wire to GPIO 4 (which is pin 7 on header P1) to act as an antenna, and tune an FM radio to 103.3Mhz

The antenna is optional, but range is reduced from ~100 meters to ~10cm without the antenna. The sound file must be 16 bit mono wav format.

 sudo python
 >>> import PiFm
 >>> PiFm.play_sound("sound.wav")

http://www.boboc.net/wiki/uploads/Main/pifm.tar.gz

http://omattos.com/pifm.tar.gz

sudo ./pifm left_right.wav 103.3 22050 stereo

 # Example command lines
 # play an MP3
 ffmpeg -i input.mp3 -f s16le -ar 22.05k -ac 1 - | sudo ./pifm -
  1. Broadcast from a usb microphone (see arecord manual page for config)

arecord -d0 -c2 -f S16_LE -r 22050 -twav -D copy | sudo ./pifm -

How to change the broadcast frequency

Run the ./pifm binary with no command line arguments to find usage.

The second command line argument is the frequency to transmit on, as a number in Mhz. Eg. This will transmit on 100.0

sudo ./pifm sound.wav 100.0

It will work from about 1Mhz up to 250Mhz, although the useful FM band is 88 Mhz to 108 Mhz in most countries. Most radio receivers want a signal to be an odd multiple of 0.1 MHz to work properly.

http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter

New version with RDS

pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code] [-ps ps_text] [-rt rt_text]

All arguments are optional:

    -freq specifies the carrier frequency (in MHz). Example: -freq 107.9.
    -audio specifies an audio file to play as audio. The sample rate does not matter: Pi-FM-RDS will resample and filter it. If a stereo file is provided, Pi-FM-RDS will produce an FM-Stereo signal. Example: -audio sound.wav. The supported formats depend on libsndfile. This includes WAV and Ogg/Vorbis (among others) but not MP3. Specify - as the file name to read audio data on standard input (useful for piping audio into Pi-FM-RDS, see below).
    -pi specifies the PI-code of the RDS broadcast. 4 hexadecimal digits. Example: -pi FFFF.
    -ps specifies the station name (Program Service name, PS) of the RDS broadcast. Limit: 8 characters. Example: -ps RASP-PI.
    -rt specifies the radiotext (RT) to be transmitted. Limit: 64 characters. Example: -rt 'Hello, world!'.
    -ctl specifies a named pipe (FIFO) to use as a control channel to change PS and RT at run-time (see below).
    -ppm specifies your Raspberry Pi's oscillator error in parts per million (ppm), see below.

By default the PS changes back and forth between Pi-FmRds and a sequence number, starting at 00000000. The PS changes around one time per second.

https://github.com/ChristopheJacquet/PiFmRds

Changing PS and RT at run-time

You can control PS and RT at run-time using a named pipe (FIFO). For this run Pi-FM-RDS with the -ctl argument.

Example:

 mkfifo rds_ctl
 sudo ./pi_fm_rds -ctl rds_ctl

Then you can send “commands” to change PS and RT:

 cat >rds_ctl
 PS MyText
 RT A text to be sent as radiotext
 PS OtherTxt
 ...

Every line must start with either PS or RT, followed by one space character, and the desired value. Any other line format is silently ignored.