Note: there is an update to this post.
There is a nice hack for a Raspberry Pi where you can turn it into an FM transmitter. Â While this isÂ illegal in most countries, the range is quite limited so it’s fairlyÂ unlikely you’ll go to prison. The only hardware needed is your Raspberry Pi and a piece of wire attached to pin 7 (GPIO 4) of the GPIO connector. Â The length of the wire depends on the frequency you are transmitting on – roughly speaking, it should be 299/(frequency x 4) metres long. Â So 103 MHz is 725 mm. Â Or if you are using inches, 299/(frequency x 0.1016) inches.
It’s very easyÂ to transmitÂ internet radioÂ using just one line of Bash but if, like me, you have a few thousand MP3s , there’s no quick and dirty way to pump them out to the transmitter.
Until now. Â Behold the PIrate Radio Juke Box (pirjb).Â If you can think of a better name for it, please leave a comment. Â A couple of Bash scripts, a minor alteration to the pifm code and a reckless disregard for radio licensing regulations is all that is needed to listen to your collection on any FM radio. Â You can repeat and shuffle with either a playlist of MP3s in a file or point it to the directory the MP3s live in and it’ll scan them and make its own playlist.
Also included is a web server to show you the currently playing track. Â Using your browser, you can skip to the next track or shut everything down and turn the transmitter off. Â Note that you can’t turn it back on with the web interface yet. Â That’s the next thing on the to do list. Â You can get to the page by going to http://your_pi_address:8080/ Â The “8080” is set in the pirjb.sh file, at the top.
Note that I doÂ not condoneÂ or encourage the use of transmitting equipment without the proper license. Â This article is presented purely as an exercise in theoretical programming. Â Your statutory rights are not affected. Â Your home may be at risk if you set fire to the curtains.
You need to have the following packages installed: sox, netcat, mp3info. Â Use
sudo apt-get install sox netcat mp3info
to install them.
Copy the pirjb archiveÂ to an empty directory on your Pi and extract the files with
tar zxf pirjb.tgz
You need to edit pirjb.sh. Â The top few lines are where things like the transmission frequency, path to the scriptsÂ and the port for the web server are defined. Â There is also a line for the compander settings for sox in order to have an AGC. Â If you didn’t understand that last sentence, don’t change that line. Â I’ve also included the source for the pifm binary included in the archive. Â There is a very minor change to it from this one – calling it with no parameters turns off the transmitter. Â Please do compile it and use it instead of the binary I’ve put in the archive. Â You shouldn’t really be running binaries from random geezers on the interwebs anyway. Â And I am sometimes quite random.
You need to make pifm run as root using setuid in order for the transmitter to work. Â Do this with:
sudo chown root:root pifm sudo chmod 4755 pifm
To run it use:
pirjb.sh -d <directory name> Â or
pirjb.sh -p <playlist>
Switches are -s to shuffle the track order, -r to repeat the playlist indefinitely. Â The playlist file should have the full path of eachÂ mp3 you want to playÂ perÂ line, i.e.
/home/naich/music/Wombles Christmas Special/01 Wombling Christmas.mp3
/home/naich/music/Napalm Death/Scum/Human Garbage.mp3
… and so on.
Have fun playing with it and do not use it becauseÂ it is illegal to do so.
Files included in the archive:
- pifm : The transmitter binary
- pirjb.sh : The jukebox script. Â Edit the first few lines for your system.
- pirjb_webserver.sh : The webserver script. Â No need to edit it.
- pirjb_template.html : The template for the web server page. Â SeeÂ pirjb_webserver.sh for information about using it. Â Or just look at the file itself and have a guess. Â It’s not hard to see what’s going on.
- source/pifm.c : The source for pifm. Â Compile withÂ g++ -O3 -o pifm pifm.c then copy over the top of pifm. Â Don’t forget to chown and chmod the compiled program.
One Reply to “Pi-rate Radio Jukebox”
Well done. This looks really great. I can’t wait to play around with it
Comments are closed.