Categories
amplifier electronics Linux Raspberry Pi

Adding radio streams to the cooler with a Raspberry Pi

Using a Raspberry Pi and the program MPD to enhance my audio cooler

Introduction

In my previous blog post I finished my audio cooler. It’s a small cooler with a tiny audio system that nevertheless sounds good. The only way to control the audio is through a wired connection. It would be a nice addition to have some kind of remote control either by WiFi or Bluetooth. While testing the cooler I’ve got the idea to connect a Raspberry Pi A+, that was still unused, to the cooler and stream audio over WiFi to the Pi.  This could be useful for a garden party or BBQ where WiFi is available and I don’t want to attach the smartphone to the cooler. In this blog post I’ll share my experience with installation and operating the software needed for this project on the Pi.

P1020957
Raspberry Pi A+ (in it’s Pimoroni Pibow case) connected with the headphone jack to the cooler. The Pi has a small Edimax Wifi adapter.

Installing music software on the Raspberry Pi

Since I run the Raspberry Pi headless I use SSH login to the Pi. SSH is available for most operating systems with the notable exception of Windows. I already had Raspbian installed on the Pi so first I updated the OS.

sudo apt-get update
sudo reboot -h now

Next I created a .conf file for the Edimax WiFi USB adapter. I learned from a previous project that, for a good remote connection, the sleep mode of the Edimax needs to be disabled. In the /etc/modprobe.d folder on the Raspberry Pi a file needs to be created with the name 8192cu.conf (8192cu is the name of the Realtek WiFi chip where the Edimax is based on).

cd /etc/modprobe.d
sudo nano 8192cu.conf

Add the following line in the nano editor and save the file

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

reboot again

sudo reboot -h now

Now I needed software on the Pi that allows me to remotely play (and organize) music. I installed the MPD (music player daemon) and the very lightweight MPC (music player client) and the server/client combination seemed perfect for this purpose. There are many other clients for MPD, even for Android and iOS, but for now MPC is good enough. To install MPD and MPC on the Pi:

sudo apt-get install mpd mpc

According to some sources on the internet a sound driver (sudo modprobe snd-bcm2835) should be installed on the Pi however I found it was already installed, probably with Raspbian.  This can be checked with the lsmod command. With MPD and MPC installed I’m finally able to stream a radio station from my Pi to the cooler but I needed to add stream urls of my favorite stations. Here is an example.

mpc add http://icecast.omroep.nl/radio1-bb-mp3

To play the stream

mpc play

To save the playlist

mpc save aplaylist

The file with the name aplaylist.m3u file is created in the folder /var/lib/mpd/playlists with the above url of a stream in it. Of course other urls can be added to the playlist. I’ve found this list very helpful if you’re looking for (Western) European streams.

Adding music to a playlist

To create a playlist of music that is stored somewhere as mp3’s just add these files to the folder /var/lib/mpd/music on the Pi. Before the files are copied however the permission of this folder has to be changed. That is done by adding write permission to the group and by changing the group to audio (which is currently root).

sudo chmod g+w /var/lib/mpd/music
sudo chgrp audio /var/lib/mpd/music

Now the mp3’s can be copied. To create a playlist of these mp3’s first clear the current playlist, create a new one by adding mp3 files and save the playlist.

mpc clear
mpc add /var/lib/mpd/music/my_cool_music.mp3
mpc save cool_playlist
mpc update

The last command updates the database of MPD. By adding more files the playlist increases in length. To play the playlist use the same command as above (mpc play).

Conclusion

A internet stream over WiFi to the cooler is a nice addition. MPD is a very stable music player with lots of different clients, perfect for this kind of projects. With MPC I can easily add streams, create playlists, play music or even store mp3’s on the Pi. Unfortunately WiFi with a Pi has some downsides too.  The Raspberry Pi takes up space in the cooler and it will drain the small battery fast. Therefore as a next step I’ll try bluetooth because it adds less weight to the cooler and has less power consumption.

Leave a Reply

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

Discover more from HomeHack

Subscribe now to keep reading and get access to the full archive.

Continue reading