Introduction: A Juke Box for the Very Young... Aka Raspi-Music-Box

Inspired by the instructable "Raspberry-Pi-based-RFID-Music-Robot" describing a music player ROALDH build for his 3-year-old, I decided to build a juke box for my even younger children. It is basically a box with 16 buttons and a Raspi 2 inside which plays songs via the attached stereo whenever any of the buttons are pressed.

What you need:

  • A Raspberry Pi with power supply
  • 16 buttons - the kind that are temporarily closed when pushed (or however many buttons you would like - advise: not more than you have input pins... ;) ) I used this one: button for €0.50)
  • some thin wire
  • one 10kOhm and one 1kOhm resister per button (unless you want to rely on the internal pull-up/down resistors of the Raspi, then you can skip this)
  • stripboard
  • female header (2x20 pin)
  • some thin wood to build the box (I used 2 sheets 5x400x400mm for the front and back plus a 2000x50x5mm strip to cut the sides from)
  • 24 screws and a bit of glue to put the box together
  • some paint to make it colourful
  • audio cable to connect the Raspi to your stereo or active speakers (jack to whatever you need on the other end)
  • tools: a soldering iron, wire clippers, wire stripper ideally, saw, drill, screw driver, paintbrush...
  • optional: USB Sound Card if you want the music to sound good
  • optional: wifi card if you would like to connect to an old Raspi without opening up the box

Please note that this is my first instructable and I did this project quite a while ago... I am making it as I keep on being asked about the VLC way of playing the songs in the comment section of the instructable mentioned above (the mplayer used there is no longer supported as far as I know). I know these instructions are not very good, but hope it is possible for you to follow... if not, please also look at the original instructable and please leave comments below telling me where you got stuck... I will then try to improve...

Step 1: Build a Box...

So the first thing you need to do is build a box... I made mine quite big because I left some space beneath each button for a label... I planned to print out some pics for each song, laminate them maybe and blue tag them beneath the buttons... lesson learned: by the time you print the labels, your kids know all the songs by hard and are demanding you to change some... So next time I would build a smaller box and put the buttons closer together...

So, back to my box... I bought two sheets of plywood 400 x 400 x 5 mm and a 2000 x 50 x 5 mm strip...then the first, most important step: my daughter was allowed to paint the front panel in her choice of colours... :) While she was painting I cut the long bit into 5 strips - two 400 mm long, two 390 mm long and the left overs... ;) these I glued to the back of the freshly painted sheet... then I drilled 12 holes from the outside and screwed in 12 screws... I then carefully aligned the other sheet on the back, drilled another 12 holes for a further 12 screws to close the box once I was done. (I know 12 screws might be a bit overkill but kids are strong... :) )

At one side I used a file (you could use a dremel to speed things up) to cut out a bit of the wood to pass through the cables. I then also drilled the holes for the 16 buttons and installed them.

Step 2: Wire Up the Buttons

So now you got a box with 16 buttons... next you need to wire these up... I connected one of their poles to ground in a daisy chain fashion. Ideally you will have little connectors to do so... I soldered them on, which was a major nightmare and will cause even more problems if I ever have to take any of the buttons out. Then I attached their other poles to a red wire each... These I then soldered to the connector board you can see lying in the middle...

Which button to which pin? Button 1-16 in this order: GPIO 18. 27, 17, 04, 23, 24, 22, 05, 16, 12, 06, 13, 21, 20, 19, 26. Please also check the "catch button press events section" in the code later.

(Please do not ask me what the rolled up wires were for... I can not remember)

Step 3: Optional: Making a Board With Pull Up and Pull Down Resistors

If you are unsure what pull up and pull down resistors are, you should easily find loads of info online. The raspi has some built in ones or you can do external ones as I did here. This step is optional as I don't think you really need it.

So why did I do it? Sometimes the music started playing when I switched on/off appliances in the flat. I first thought it was picking up electro magnetic waves or something. So I added the pull-up/down resistors... As this did not improve the situation, I added some capacitors in addition. This still did not help... the next thing I wanted to try was to cover the inside of the box with aluminium foil as shielding. As the problem stopped when we moved house, I never ended up trying this... So what was the problem? I do not know... it may have been variations in the power line?

Conclusion: I would advise you to first just connect the buttons directly (you will see in the code later which button goes on which pin) and only do this step if you have some issues. I hope you can see from the pictures above how I did this. Basically there is a bar to putt on the header in the middle and then on each side I connected the two resistors and the cables from the buttons in one row.

Step 4: The Python Code

Attached here you will find the code (in python) that manages the musicbox. I added quite a few comments so hopefully it is self explanatory. Just in case here a quick explanation. It is best to start reading the variables section at the top and then skip all the way to the bottom.

At the bottom you will find a loop, which runs all the time. It first checks whether a certain sequence of buttons was pressed - this was my way of using some parental control. Then there are the functions that play the music.


Above the main loop you will find some event detects - these are executed if one of the buttons are pressed. Each button calls the ButtonPress function passing an identifier.

So how to make it play the music? To keep it simple, I just generated one folder for each button. Whatever mp3s you put in these folders, the function adds to the play list.

Please note, if you did not use physical pull up resistors, you will need to change the section with the BCM numbering to this:

# setup using BCM numbering
GPIO.setmode(GPIO.BCM)
GPIO.setup(04, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(05, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(06, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(19, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP)

Step 5: Setting Up Your Rapsi

You will also need to set up the raspi of course... I just used the standard Noop installation. I am sure you will find loads of instructions on how to do that...

To use python you will need to "sudo apt-get install python-dev"

My program uses VLC to play the music:

  • I got the Python connection from here (hope this is still up to date): https://pypi.python.org/pypi/python-vlc#downloads
  • Then I installed it using "sudo python setup.py install"
  • Then installed VLC "sudo apt-get install vlc"
  • Stick the files vlc.py and vlc.pyc into the same directory as your program

  • More info at https://pypi.python.org/pypi/python-vlc/1.1.2

My notes say you also need to install the following to access the GPIO Pins from python (but this may be out of date):

To make your program run, you will have to call "sudo python yourfilename.py".