This is by far the most complete and comprehensive guide to using a Raspberry Pi for anything I have seen yet!
Get on it people!
You have a ton of options for accessing your computer’s music library from your stereo, but most require a bit of technical know-how to actually use. You can build a jukebox with a Raspberry Pi, a tiny micro-computer, that anyone can use, even if they don’t know what a Raspberry Pi is.
When you’re done with this project, you’ll have a tiny, touch screen jukebox in your living room that can play, control, and pick songs from your music library on another PC (or your network attached storage), then play them on your stereo. The interface here is easy to understand, so it’s great for parties or a house where a few non-geeks might want to get in on the playlist without learning a complicated system, your computer, a Wi-Fi password, or anything else. Better still, it all works on its own network, so no need to worry about pairing devices or any of that. To finish this project, you’ll need a little knowledge of the command line, but that’s it.
What You’ll Need
- A Raspberry Pi (The model B, B+, or 2 will work)
- A power cable for the Pi, ethernet cable (or Wi-Fi card), SD card, and a keyboard for setup
- A touch screen (we used this one, the PiTFT from Adafruit)
- A home server or computer with MP3 files on it
- A stereo and speakers to connect your jukebox to
- A case (optional, but people will be touching it, so you should get it in something. The newofficial case will work great)
Step One: Install Raspbian on the Pi
First things first: you’ll need to set up and install Raspbian. If you’re using the PiTFT touch screen display I did, it’s a lot easier to set it up with Adafruit’s custom Raspbian image. You’ll install the image on your SD card the same way as with Raspbian, but the operating system will already be configured for the display. You can follow our guide to make an image here, but here’s the short version:
- Download the latest version of Raspbian and unzip the .img file inside.
- Download Win32DiskImager and unzip the application (.exe file) inside.
- Insert your SD card into your Windows PC using a card reader.
- Open Win32DiskImager.exe, the application you just downloaded, by double-clicking on it. If you’re running Windows 7 or 8, right click on it and choose “Run as Administrator” instead.
- If your SD card isn’t automatically detected by the application, click on the drop-down menu at the top right (labeled “Device”) and choose it from the list.
- In the image file section of the application, click the little folder icon and choose the Raspbian .img file you just downloaded.
- Click the Write button and wait for Win32DiskImager to do its thing. When it finishes, you can safely eject your SD card and insert it into your Raspberry Pi.
- Download the lastest version of Raspbian and unzip the .img file inside.
- Download RPi-sd card builder (be sure to pick the appropriate version for your installed version of OS X) and unzip the application.
- Insert your SD card into your Mac using a card reader.
- Open RPi-sd card builder. You’ll immediately be asked to choose a Raspbian image. Choose the .img file you downloaded earlier.
- You’ll be asked if your SD card is connected. Since we inserted it earlier, it is, so go ahead and click Continue. You’ll be presented with SD card options. If you only have one inserted, you won’t see anything else in the list and it’ll be checked. If not, just check only the card you want to use and click OK.
- Enter your administrator password and click OK.
- You’ll be asked if the SD card was ejected. This is supposed to happen, as the application needs to unmount it so it can perform a direct copy. Double-check that your SD card is no longer available in the Finder. DO NOT remove it from your USB port. When you’re sure, click Continue.
- RPi-sd card builder finishes prepping your SD card, safely eject it and insert it into your Raspberry Pi unit.
Step Two: Hook Up Your Display
The Raspberry Pi has a GPIO (general-purpose input/output) that the touch screen fits into. If you look at your Raspberry Pi, it’s the set of pins on the corner. If you haven’t already, go ahead and click the display onto your Raspberry Pi. When it’s hooked up, plug in your keyboard, ethernet cable (or Wi-Fi adapter), then the power cable. You’ll be asked to calibrate the touch screen. Follow the on-screen instructions and you’ll be all set.
Step Three: Share Your Computer’s Music Library
Before you start working on the Raspberry Pi, you should set up music sharing on your home computer. The process is different for both Windows and Mac.
- Navigate to your computer’s music folder.
- Right-click the folder and select “Share with” and select domain. If you’re only on a home network, you can keep it public and it’ll only be available to other computers on your home network. Otherwise, select the password protected sharing, then enter a password.
- Make a note of the folder’s location and your computer name (It will be something like ThorinPC/Music).
- Open up System Preferences.
- Click the “Sharing” icon.
- Make sure the “File Sharing” box is checked.
- Click the “+” underneath shared folders, select your music folder, then click “Done.”
- Back on the Sharing menu, select “Options...”
- Select “Windows File Sharing” and enter your password. This will make it easy for the Raspberry Pi to grab your files.
Now that your home computer’s sharing its music library, you can return to your Raspberry Pi.
Step Four: Install and Configure MPD
The foundation of this project is Music Player Daemon (MPD). It’s a server-side application for playing music. This means it has no graphic interface, it simply allows your Raspberry Pi to play music files. You won’t need to dig around in the command line to actually use this project once it’s set up, but you will need to for the initial setup process. First, you’ll need to download MPD and MPC (the controller). When you booted up your Raspberry Pi earlier, you should have ended up at the command line after the touch screen calibration. If not, and you’re in Raspbian, tap the menu icon and select “Log Out.” You’ll do all the work in this guide from the Raspberry Pi’s command line, type in:
sudo apt-get install mpd mpc
Wait for that to install. Once it’s finished, you should change a couple of settings by running:
sudo nano /etc/mpd.conf
Find the line that starts with:
and delete the # in front of it to uncomment it. Press CTRL+X and select Y to save and exit.
Step Five: Set Up the Music Library
Next up, you’ll need to point MPD to your music library. For this, you’ll make a folder, then mount your music library in it. You’ll need to do most of this with the sudo command because you need root privileges to get everything installed and working properly. Start by making a folder:
sudo mkdir /mnt/music
Next, we’ll make sure it mounts when the Pi boots. Run this:
sudo nano /etc/fstab
Then add this line, substituting Computer name with the info and /folder name you gathered in step three for your music folder location:
//Computername/foldername /mnt/music cifs guest,uid=1000,gid=1000,iocharset=utf8 0 0
It should look something like this:
//WindowsPC/music /mnt/music cifs guest uid=1000,gid=1000,iocharset=utf8 0 0
Note: if you require a login to your shared folders, you’ll also need to replace guest with username=yourusername,password=yourpassword.
When you’re done, tap Ctrl+X to save and exit. Next, let’s test and make sure the mount is working properly. Type in:
sudo mount -a
If you don’t get an error message, it’s mounted correctly. Now go ahead and take a quick look to make sure all your music files are there. Run this command:
ls -l /mnt/music
You should see all your music files. If that’s all in order, you’ll need to create a symbolic link for MPD so it knows where to go looking for those files. Type in:
sudo ln -s /mnt/music /var/lib/mpd/music
Now, MPD should be all set. You just need to scan your music library to get everything in there. Type in:
Depending on the size of your library, this will take a little while, so let it do its thing.
Step Six: Configure Networking and USB Drive Access
Next up, you’re going to configure Zeroconf, which will allow you to control your jukebox from other devices if you don’t feel like walking over and using the touch screen. Type in:
sudo apt-get install libnss-mdns
When that’s complete, start it up:
sudo service avahi daemon restart
Now you can optionally use a mobile phone app like MPDroid for Android or MPDluxe for iOSas a remote control for the Pi Jukebox. Before we get to that, you can also set up the jukebox to read files off a connected USB drive, which is handy if friends come over with a bunch of MP3s on a flash drive. Sadly, you can’t just plug in your phone to get access to the music because chances are the Raspberry Pi won’t be able to recognize it. To turn on USB support, type in:
sudo apt-get install usbmount
Then point MPD to the USB sticks:
sudo ln -s /media/ /var/lib/mpd/music/
That’s it. You should be able to play music from just about anywhere now.
Step Seven: Install the Jukebox Software
Right now, your Pi can access your music and play it from the command line. That’s pretty boring. Let’s get the nifty touch screen interface set up.
We’re going to use a program called Pi-Jukebox for this. It’s essentially a frontend for MPD that allows you to use the touch screen to control music playback. Installation here is pretty straightforward. From the command line, run:
git clone https://github.com/mark-me/Pi-Jukebox
This downloads all the files needed to the Raspberry Pi and into the Pi-Jukebox folder. Before we can run it, we need to install Python:
sudo apt-get install python-pip
Once that’s installed, it’s time to run the Jukebox program.
Step Seven: Run and Use the Jukebox Software
To launch the jukebox, you only need to type in one command:
sudo python pi-jukebox.py
If everything goes as planned, you should now see the Pi-Jukebox software on your touch screen. Here’s a breakdown of what each button means:
For the most part, the interface works as you’d expect. You can swipe up and down to browse your library, tap on any of the controls to start and stop play, and tap on a selection to load it up. Pi-Jukebox works just like a jukebox, so you’ll add each of your selections to a currently playing playlist and go from there. There isn’t a direct means to simply play an album without adding it to a playlist.
The settings options are pretty straightforward as well, but it’s worth popping in there and checking them out. You can set up your jukebox to shuffle, repeat tracks, and more. But for all intents and purposes, you’re set up and ready to start listening to music. If you haven’t already, connect your Pi into your stereo and start jamming.