Raspberry Pi Radio

Setting up your Raspberry Pi to send music over FM could be used to play the same music in every room of the house and even outside at the same time, rather than just one set of speakers, without the latency of some wifi enabled products.

I chose to control what it is playing with ampache, a web based music player that plays via your internet browser and in our case, it sends it to MPD, a music streaming server. MPD then sends it to PiFmRds to send it over the airwaves.

This can’t really be followed as a tutorial without some prior knowledge but I thought I would give you the idea of what is involved in setting up a short range FM radio station. if you do pop an antenna on it (which you shouldn’t for legal reasons) it will not go much further than the walls of your house with a 10cm wire. With a newer radio, it can broadcast a station name and some scrolling text with your audio.

If you are using the 3.5mm headphone jack for your speakers on your pi at the moment, you are going to have a bad time. When PiFmRds broadcasts you will hear an incredibly loud squeal from your pi’s speakers regardless of your volume and overclocking the speed of your pi will make it worse. So only use your HDMI audio as your normal audio output

When you are not playing music the radio will stop transmitting so you will hear static again so make sure you create a nice long queue of music.

Due to Youtube being a spoil sport when it comes to playing music in your video’s here is the volume turned down and the sound of… I have no idea what that sound is.

The white wires connect red for the antenna on the right (GPIO4) and black for ground on the left (ground is not required for transmitting over the air)

This should not be your first project, it could inspire one or be picked apart but be warned, this won’t make sense to everyone

Use the instructions on the following link to Install PiFmRds

https://github.com/ChristopheJacquet/PiFmRds

Ideally you want to type

sudo apt install ampache mpd

but I gave up trying to get ampache to install with apt on my pi 4 due to a dependency issue with raspbian at my end so I used the next command instead and then installed the rest manually by downloading the latest version from http://ampache.org/

sudo apt install mpd apache2 mariadb-server mariadb-client php php-common php-mysql php-curl php-xml composer php-gd ffmpeg

It will ask you to set a password for mariadb, you will need it in a second when you run the following command to turn off insecure options in the database server

mysql_secure_installation

The web server will need AllowOverride All turned on to allow ampache to access your music collection so you don’t have to put it in your web servers root folder. They do this so people can’t download it all of your music without logging in using a couple of .htaccess files

put the contents of the zip file you downloaded in /var/www/html and enter your pi’s IP address into your browser to start setting it up

Enter your databases root password and tick Create a database user with the bottom tickbox. Don’t stress too much about the username and password for the ampache user, you won’t be using it. it is for ampache to talk to the database behind the scenes.

At the end of the process, it will create a conf file and a couple of .htaccess files that you will need to download and put into the appropriate folders but keep in mind you might have to rename them. For example downloading all of them, files like htaccess(2) will have to be renamed to .htaccess again.

Next you need to open your new ampache site and add a localplay instance so ampache knows how to talk to mpd. by default, mpd doesn’t use a password

Then add some music

At this stage you could use the web player in the drop down box, up in the top right corner to test everything so far. When its all running, it will transmit using localplay. You can do local play to FM and web players at the same time

comment out the ALSA output

and add the following at the end of your outputs (you can only have one output)

audio_output {
type "pipe"
name "PiFm"
command "sudo sh /home/pi/piradio.sh"
format "44100:32:2"
}

the piradio.sh script that it runs contains one big line that pipes mpd’s output as a WAV file to PiFmRds

sox -t raw -b 32 -c 2 -r 44100 -e signed-integer - -t wav -b 32 -c 2 -r 44100 - | sudo /home/pi/PiFmRds/src/pi_fm_rds -ctl /home/pi/rds_ctl -freq 88.0 -ps RPi-Live -rt "Streaming from a Raspberry Pi" -audio -

Thats it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Theme: Overlay by Kaira