Introduction: Raspberry Pi Music Player
Did you ever come home and wanted some background music to chill to without having to turn on the computer, your phone or any other device?
I had said problem.
In the following Instructable I'm showing you my concept of an offline music player operated by analog switches. (the music comes from a built in USB stick #oldschool)
I'll try to write this Instructable easy so even the biggest NOOBS can do it, even though I used Raspbian (bad joke explained in step 4)
Note: I have no experience with coding so I ended up working with a more experienced coder( thanks Raffael :) My personal experience came from watching a video on Youtube as preperation so if you find mistakes in the code or the Instructable in general, please comment.
Step 1: Planning
First you need a plan
*) The intended use is background music
*) I don't want to stream or do any other stuff like that just yet. The usb stick is going to hold more music that I can listen to in a year so that should be fine for now. Maybe I'm going to use the Wlan module which is built into the raspberry to connect to my NAS server for a bigger music selection.
*) No GUI only 3 switches connected to the gpio pins of the Raspberry pi
*) leds over the switches so you know witch playlist is running (optional)
[ *) Speakers with built in amplifier conect to the soundcard witch is connected to the Raspberry pi. ]
-> more on that later
And most importantly: if this is done, I don't want to deal with it ever again.
Step 2: Material List
1. a Raspberry pi (I used the modell 3B but an older one should be fine too. Actually you could use something even less powerfull like an arduino but you'd have to add modules for an SD card and audio)
2. a soundcard, not necessary but the one which is built in isn't too good (I started with the Hifiberry DAC, which is not compatible so I ended up not using a soundcard at all since the quality was fine for me and I wanted to finish the project :)
3. some jumper cables
4. speakers with a built in amplifier (you could use speakers without and amplifie (amplify?) them seperate but it's easyer/cleaner that way)
5. switches for the playlists: I used 3 for the playlists [you could use more or less, you would have to modify the code then] and one for shutdown
6. some scrap wood or a box of any kind (3 options in step 7/8)
7. a computer/hdmi cable to connect the pi
8. Mouse and Keyboard
9. a power cable to power it up
10. some leds (optional)
Step 3: The Code
Like I said I have no experience with coding so I went to a more experienced coder (thanks at this point Raphael). I used python because the Raspberry pi works with python and it's not too hard to learn the basics.
The player works with two seperate programmes, one to start the playlist and one to kill it. They are both in a loop so this program once started will only end if you pull the plug (what you shouldn't do, USE THE KILL-SWITCH!)
Step 4: The Raspberry Pi
So In this step we are going to set up the Raspberry pi. I used Raspbian as an operating system but you can use Noobs or any other system if you like (note that some steps may be different on other systems).
First you set it up
(you can read a detailed guide on the internet or watch a video on youtube, I'm not going to go into that, it's going to take about 10min max.)
Then you add the two scripts to the autostart in the raspberry. You do that by writing "sudo nano /etc/rc.local" into the command line and adding the names and the path where you saved the files into the bottom of the page before the "exit" line. In this case:
(you have to add the "&" at the end since the project is a loop and should work in the background). Do that with the kill and the original script.
Now you press "Ctrl X" to leave
Now the soundcard.
I would use a soundcard because the 3.5mm audio jack on the pi isn't too slamming
The soundcard the store sold me was the oldest there is so combined with the newest pi this caused some problems (pretty pissed at this point, I spent 30€ on that card). So I ordered a cheap ass (6€) USB soundcard on amazon.
But no worries you have to set up the USB soundcard like you have to when using a GPIO soundcard. So you don't miss out on that (more on that in chapter 6)
Done as easy as that
Step 5: The USB Stick
Now the USB Stick has to be EXACTLY the same as mine or you have to change the program.
1. Rename the stick into "TRANSCEND" If you want to use another name you would have to change the name in the scripts (As you may noticed I am a lazy. So I didn't rename the stick, it would be much more beautiful sure, but it's not necessary so...)
2. Create 3 playlists called Pl.1, Pl.2 and Pl.3 with songs in them. Like above same name bla bla bla
3. The Musicplayer on the Raspberry pi won't use some signs and letters so I downloaded a renamer (I used Ant renamer) that renamed the songs in 8 random numbers so you should do that too
4. Add the scripts and songs in the Playlist folders
Step 6: Last Touches
Now we connect the Raspberry pi with the soundcard, the switches, the leds and power it up.
Use jumper cables to connect switches and leds
The USB soundcard caused some trouble but that's manageable. You have to check the Internet for instructions how to install it since this step varies depending what card you use :/. Basically you deactivate the build in soundcard and use the new one.
However if you are lucky you just have to plug it into a free USB port and done. Be prepaired to play around with the settings. At this point I really wanted the thing to be done so I proceeded without the soundcard.
Test it with the Display connected and without before you build a box around it. If it doesn't work check the USB stick. Did it rename himself? Is it damaged?
Step 7: The Box
Now the box.
You have 2 options
1) So If you want do it style you would laser cut (or CNC) a box out of slices of wood with joints and everything.
2) Another way is to take an existing box and use it as housing. First I did that but I didn't like the look so I did it as following (step 8)
Drill 3+3 holes in the top of the box and install the switches (and the leds if you use some).
Drill a hole in the side for the power (the lazy way is to simply use a USB cable as built in power without removable cable), however I suggest using a USB extension cable for power so if the power cable breaks you don't have to take the thing appart -> which results in work what we try to avoid
Now that everything is ready connect the pi and the speakers.
Step 8: The Hipster Way and Finishing the Case
This is for the creative individuals who want to show off their skills.
For this option you can use either wooden planks and glue/screw them together to create a box or you do the hard way of the hard way and carve out an existing block of wood to put the pi inside.
I saw those floating shelves and wanted to use that technique. So I went into my garden, took an old piece of wood and checked if the speakers could stand on it (the width).
The shelve should look like a solid, floating piece with only the switches sticking out so I carved it out from the bottom. I let a kind of "lip" on the front so you dont see the cutout
I hope my drawings can help you to get an overview
Finishing the case:
So if you have a the box the process is the simple. Drill 3+3 holes in the top of the box and install the 3 switches and the 3 leds above if you use some.
Drill a hole in the side for the power (the lazy way is to simply use a USB cable as built in power without removable cable), however I'm going to overcome my lazyness and use an IEC socket for practicality because I break my cables on a regular basis.
Now that everything is ready connect the pi.
To mount it on the wall I choose to drill 2 big holes in the backside and mount it with 2 hooks (picture above)
And we're done.
Pay attention to the power cords running through the walls while drilling into it. Hitting them would be a truly shocking experience. Ha got ya there.
Step 9: Debugging
If you worked properly you don't need this step
If you work like I do, I guess that you're going to need it
So, what are the possible mistakes?
*) You didn't rename the songs
*) Typos in the path in the Autostart (rc.local)
*) Typos on the USB stick/Playlists
*) You didn't rename the stick (or it renamed itself after an incorrect shutdown)
*) You didn't use the turn off switch and pulled the plug. If it wount work check the stick and the pi for errors.
*) The connection from the buttons to the pi got loose
*) the sd card broke, literally (yes that really happened to me don't ask me how) or figuratively
*) the power shut off
Every single one of those mistakes happened to me while building
Step 10: Done!
On that bombshell it's time to end. Please comment any improvements you may find and post your music box. Thanks for reading, have fun and take care.