Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Blueprints

You're reading from   Raspberry Pi Blueprints Design and build your own hardware projects that interact with the real world using the Raspberry Pi

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784392901
Length 284 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Raspberry Pi Pirate Radio FREE CHAPTER 2. Portable Speaker System 3. Mini Retro Arcade Cabinet 4. GPS-enabled Time-lapse Recorder 5. Home Theater PC 6. Outdoor Weather Station 7. Home Security System 8. Remote-operated Robotic Arm 9. Magic Mirror 10. Bottle Xylophone Index

Setting up the pirate radio

It's now time to download and set up the PiFM software, which will allow you to use the GPIO header as an FM transmitter. First, we'll need to download the software using the following commands:

wget http://omattos.com/pifm.tar.gz
tar -xzvf pifm.tar.gz

This will get the gzipped archive that contains the PiFM software, the Python library, and some test files and uncompress them.

For now, a single male to male 0.1 inch pin jumper will suffice as an antenna; this should be connected to GPIO 4 (pin number 7) on the GPIO header and made to stand as upright as possible to ensure the best range (refer to the following image):

Setting up the pirate radio

You are now ready to test the setup with an FM radio; firstly, you will need to choose a frequency that will not overlap with any licensed broadcasts in your area and is within the FM radio transmission range in your area (usually between 88 Mhz and 108 Mhz). A lot of radios that do automatic tuning also tend to prefer frequencies that are a multiple of 0.1 MHz (for example, 99.9, 101.3, and so on).

Once you have chosen your frequency, tune your radio in to it, and run the following command on the Pi, where freq is the frequency you wish to broadcast on:

sudo ./pifm left_right.wav freq 22050 stereo

You should now hear a sample auto clip demonstrating the ability to broadcast stereo audio.

Transferring MP3 files to the Pi

For our media player, we are going to need a selection of MP3 files on the Pi SD card. There are two main ways to do this, either by moving the card back to your PC and mounting it like a regular SD card, or by using the Secure File Transfer Protocol (SFTP).

In this case, since the Pi is already running, I have opted to use SFTP. This can be done using the FileZilla (https://filezilla-project.org) FTP client. Once installed and opened, enter the same details that you used to connect to the Pi over SSH in the fields at the top of the window (using 22 for Port), and click on Quickconnect.

You should now be able to browse the filesystems of both your computer and the Pi, as shown in the following screenshot. Files can be uploaded by right-clicking on them and selecting Upload.

Transferring MP3 files to the Pi

In order to play the music you have just transferred to the Pi, you will need to install the ffmpeg utility, which is a tool that is commonly used to transcode media files and can be installed using the following command:

sudo apt-get install ffmpeg

Now that you have some of your own music on the Pi, you can try playing it by piping the output of ffmpeg to PiFM:

ffmpeg -i file.mp3 -f s16le -ar 22.05k -ac 2 - | sudo ./pifm - freq 22050 stereo

Here, file is the MP3 file to be broadcasted and freq is the frequency to broadcast it on. Since we are telling ffmpeg to provide output for two audio channels (-ac 2) and giving the stereo option to PiFM, this should give a stereo audio broadcast.

You have been reading a chapter from
Raspberry Pi Blueprints
Published in: Mar 2015
Publisher:
ISBN-13: 9781784392901
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image