An easy-to-use music player for children based on the Raspberry Pi Zero and the JBL On Stage IIIp (again)
In spring 2016 I finalized the "Musikrakete", a music player that our boys could operate without assistance. This is the third version, with all of the improvements I came up with during the last three years. It is easier and cheaper to build, the case is way smaller and much more robust. By switching to volumio the player now supports remote control from the phone and streaming services like Spotify. All of this combined with the existing features like playing MP3s from the local network and, most importantly, being easy to use even for small children. So if your children love music and audio books just like mine, this might be a project for you.
This project started in 2016, when Anica asked me if buying a hörbert MP3 player would be a good idea. At the time our boys wasted two to three CDs every week, trying to get some music out of the small player in their room. And the player in the living room also seemed to reach its end of life pretty soon due to their enthusiasm. Still, I wasn't too sure about this hörbert thing. In order to get new files on the SD card of the player, the case had to be opened, the navigation with 11 buttons seemed a little confusing and a single speaker operated with four batteries also did not seem promising to me.
I had seen a project description of an MP3 player for small children shortly before: A Raspberry Pi mini computer, connected to a webcam and speakers, reads QR codes and plays the respective track or playlist. So this was what I suggested and to my surprise it was considered a better solution right away. And I had a project.
As good as the project description seemed to be, I wanted to make some improvements on the original design: The player should detect the QR card automatically, it should have buttons for play/pause and skipping and all components should be put together in a single case. Most importantly, the MP3 files should be delivered directly from our home server. No SD card replacement needed.
Since we had an old JBL On Stage IIIP speaker lying around that wasn't used anymore due to its outdated iPhone dock connector, I decided to use this as a base. After playing around with Onshape, soldering and programming for three months, I had the Musikrakete ready by end of March 2016. It was a huge success with the boys and has been in heavy use ever since.
Over the last years I came up with some improvements on the original design and created a second version. But I always had some things in the back of my mind that I wanted to make better about both the hard- and the software and when the little brother moved into a room of his own, I knew it was time to bring all that to life. So this is the smaller, better and cheaper third version. The rocket on top is optional, by the way. But little brother would never have accepted a player that did not somehow include a rocket, since the original, rocket-shaped design is still used by the older one.
PiPlayer 3.0: Qudio
This third version now relies on volumio which can play music from streaming services like Spotify Premium or LastFM, has a nice web interface and makes configuration easy. The case is much smaller than before, which makes it sturdier and easier to print. The electronic parts are all easily obtainable standard compontents and even cheaper than before. Again, it is built on top of the JBL On Stage IIIP speaker, that can still be found on ebay for little money and provides a perfect base for a player like this.
The main component is now a Raspberry Pi Zero W, that can be run off the dock connector without an additional power source. I replaced the Pimoroni PHAT DAC with a dirt cheap audio module based on the same chip. The IR sensor that detects the QR cards is now a ready-made module which makes assembly easier. The buttons have been replaced by the ubiqitous 12 mm standard components that come with every Arduino starter kit.
- JBL On Stage IIIP - can be found on ebay for little money
Caution: The older On Stage III with the mini USB port will probably not work!
I tried several and they either did not power the Raspberry Pi properly or I had noise issues that I could not resolve.
- The case, which consists of four parts. I printed mine in standard PLA. You can also copy and modify it on OnShape.com
- Raspberry Pi Zero W with a micro SD card a pin header
- CJMCU-5102 plus a 10 kΩ resistor, some PCM5102A based module or any other I2S DAC that is supported by volumio. Search for 'pHAT DAC'. A USB sound card will not work, since the USB port is used by the webcam.
- TCRT5000 reflective sensor module
- The ultra-cheap USB webcam that can be found on ebay, aliexpress and the like (just sort for price). Some versions come with a small cable reel. This fits perfectly in the holder at the bottom of the case.
- USB A to micro USB adapter that connects the webcam to the Raspberry Pi's micro USB port
- 30-pin Apple dock adapter to micro USB and 3.5 mm audio
- White LED (preferably diffused) for illumination of the QR cards with a proper resistor
- 3 push buttons with 12 mm caps
- Jumper cables: 6x 10 cm M-F or F-F for the buttons, 5x 10 cm F-F for the audio module, 5x 20 cm F-F for the sensor and the LED
- A small sheet of acrylic glass / plexiglass (around 2 mm)
- 2 M3×20 screws, 6 M3×8 screws and 3 nuts
- 5 M3 threaded heat-set inserts
- Soldering iron, drill, screwdriver, glue gun, box cutter
- And, finally, the code
Assembling the Components
Preparing Speaker and Printed Case
Disassembling the JBL and Mounting the Bottom of the Case
In order to mount the case on the JBL, we have to disassemble the speaker and drill some holes. The screw in the center is hidden in the battery case, while the eight others are hidden under the rubber pads. Just peel them off carefully, we can glue them back on later.
After removing the screws you can upen up the case. The circuit board is fastened with another four screws that have to be removed. Then the board can be pulled out of the case carefully. The power button of the speaker is the most sensitive part here. To make life easier, you can also pull off the speaker cables from the board. Now the cover is completely separated from the bottom and the circuit board.
The next step is to drill the three mounting holes into the cover, for which you can use this template. (Make sure to print without scaling.) Finally, we need to mount the base of the printed case to the speaker case using three M3 screws with nuts. Afterwards, we can put the circuit board back in the case and put all the screws back in place.
Putting the Threaded Inserts into the Printed Parts
Now is also a good moment to put the threaded inserts into the printed parts. This is done by carefully pushing them into the plastic with a heated soldering iron. As soon as the plastic has cooled down, the inserts will stay in place and allow to close and open the connections without tearing the plastic apart. This video on 3Dhubs shows how it is done.
We put two M3 inserts into the bottom of the case, one into the cover to hold the TCRT5000 sensor and the remaining two into the curb that goes on top of the case.
Installing the Window
For the window on top of the case, we need to cut a 50 × 28 mm part of acrylic glass. This can be done with a normal cutter knife by (carefully!) repeatedly cutting along your marker line with a ruler until you can break it off.
When the glass fits into the case, point through the screw holes to mark where you have to drill. The acrylic glass can then be drilled just like the speaker case in the first step. With all the parts of the case now being ready, you can to a first test on putting everything together and closing the case.
If you are also using the CJMCU-5102 module, you will have to pull the XMT pin to high by connecting it to the 3.3V pin via a 10 kΩ resistor. This will unmute the audio output. Also, the FLT, DMT, SCL and FMT pins should be connected to the module's GND pin on the backside. That way, only a single cable connection to GND on the Raspberry Pi is needed.
The other pins are connected to the Raspberry Pi as follows:
- VCC ↔ pin 2 (5V)
- GND ↔ pin 6 (GND)
- FLT ↔ GND
- DMP ↔ GND
- SCL ↔ GND
- BCK ↔ pin 12 (GPIO 18)
- DIN ↔ pin 40 (GPIO 21)
- LCK ↔ pin 35 (GPIO 19)
- FMT ↔ GND
- XMT ↔ 10k Resistor ↔ 3,3V of the PCM5102A board
Before the camera can be put into the case, the clip on the backside has to be removed. Simply push out the pin and take it off. Now you can clip off the clip holders from the camera case.
Unfortunately, the cable also has to be moved from the back of the case, in order to be able to place the camera on top of the speaker. You can just make a small cutout with a sharp knife to make space for the cable. However, if you want to play it safe it might be better to open the case up with a screwdriver before cutting it.
With the cable out of the way, the camera can be shoved into the holder at the center of the bottom part.
Finally, the focus has to be adjusted. The best way for that is connect the camera to another computer to get a live picture. You can also do it later on, but then you will have to take a snapshot and readjust the lens in turns. It is just easier with direct feedback.
Put the cover on top for the correct distance, then check if you get a clear picture. If not, turn the lens a bit and check again until you have a sharp image.
Dock Adapter Cable
Now insert the adapter cable on the dock connector in front of the camera. It should fit in nicely without any adjustments.
The three buttons go directly in the small pockets on the bottom part of the printed case. While the front pins are put into the small holes in order to fasten them tightly, the pins on the other end should be bent up and soldered to the male end of the jumper wires. Connect the buttons to pins 10 (for PREV), 9 (for PLAY/PAUSE) and 11 (for NEXT). The other sides go to the ground pins 20, 30 and 34.
The TCRT5000 sensor module is connected as follows:
- VCC ↔ pin 4 (5V)
- GND ↔ pin 14 (GND)
- DO ↔ 29 (GPIO 5)
The pins of the module need to be bent up to fit in the case. (For some reason all the modules have 90 degree pins.) We can then use the M3 screw hole to fasten it to the top. The little potentiometer on board allows to adjust the sensitivity of the sensor in place, if needed.
My sensor permanently fired whenever I tightened the screw. Apparently the threaded insert connected two of the pins. I solved this by covering the pins on the back side with some hot glue.
The next problem was a little red power LED on the module. While being tiny, it put the whole printed case in a permanent red glow that did not look pretty and also would have been disturbing given that the player was to be put on a nightstand. I bypassed the LED with a tiny piece of wire that you can see in the pictures.
The led is put in the small holder at the front side inside the cover. Connect the long leg to pin 15 (GPIO 22) of the Raspberry Pi (with a resistor in between, if needed), the short one to pin 9 (GND). I dimmed the LED with a 220 Ω resistor even though mine could operate directly on 3.3 V because it was just too bright. The QR recognition does not need much light.
Closing the Case
Now it is time to put the remaining parts in place: Hook up the camera to the Raspberry Pi using the micro USB adapter. Also connect the two ends of the dock adapter cable to the audio module and the Raspberry Pi. Move all the cables in a place where they do not block the camera, bring up your best origami and close the case. You might need two or three attemps until everything is in the right place, but it fits in, believe me.
OK, well done. Now reopen the case, the player is still missing its SD card with the software.
Software Installation and Configuration
First of all, you will have to download the volumio image for Raspberry Pi and put it on your micro SD card. (I use balenaEtcher for that, which works fine.) Once you have done that, put it in and start the Raspberry Pi by powering the speaker.
The initial configuration is pretty straight forward. Connect to the WiFi network "volumio" that has been opened up. If it asks for a password, enter "volumio2", then click through the installation assistant. Set the output to "Generic I2S DAC", activate the software mixer and connect your network share (if any). You can also already set up plugins for streaming services like Spotify. Finally, activate SSH on the developer page qudio.local/dev (or whatever your hostname was) for the next steps.
Before you leave the SD card in the Raspberry Pi for good, you might want to shutdown volumio, put the card back into your computer and copy over the contents of the /code directory to /data/INTERNAL/qudio. (The data directory is only available after first start, which is why we had to complete the installation assistant first.)
Alternatively you can copy over the code via ssh, but doing it directly on the SD card might be easier. In addition to that, you can put some music directly on the SD card, if you want to. Everything in the INTERNAL directory will be available in volumio after a rescan.
Configuration und Test
After putting the SD card back in and booting up the player you can connect to the Raspberry Pi via SSH as user volumio. The initial password is volumio which you might want to change with
The next step is to install the necessary software packages:
sudo apt-get update sudo apt-get install fswebcam zbar-tools
Now look for the camera (it should be available under
/dev/video0) and make a test photo. You can check it out from your computer at http://qudio.local/backgrounds/webcam-test.jpg (if you set Qudio as hostname, like me).
lsusb && ls /dev/video* fswebcam -r 320x240 -d /dev/video0 -v /data/backgrounds/webcam-test.jpg
Before we go on, we need Python 3.6 on the Raspberry Pi. Earlier versions have a bug in socketio-client (which we need for remote control of volumio) and the current version 3.7 has a problem with OpenSSL, so 3.6 it is. Unfortunately, we will have to built it from the source, which takes a while.
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev cd ~ wget wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz tar xf Python-3.6.5.tar.xz cd Python-3.6.5 ./configure make sudo make altinstall
When this is completed entering
python3.6 --version should result in "Python 3.6.5" on the command line. Now add the required libraries:
sudo easy_install-3.6 -U pip sudo pip3.6 install --upgrade pip sudo pip3.6 install socketio-client sudo pip3.6 install RPi.GPIO
Now it the system should be able to run the test scripts:
# Turn the LED on and off python3.6 /data/INTERNAL/qudio/test/led_on.py python3.6 /data/INTERNAL/qudio/test/led_off.py
# Test the buttons python3.6 /data/INTERNAL/qudio/test/buttons.py # Pressing the buttons should now result in an output. After testing, stop the script with Ctrl-C.
# Test the sensor python3.6 /data/INTERNAL/qudio/test/sensor.py # Putting a card on the window should make the signal go from HIGH to LOW. After testing, stop the script with Ctrl-C.
If everything works fine, we can set up the script that glues everything together as a system service. Create a service description file with
sudo nano /lib/systemd/system/qudio.service and put in the following content:
[Unit] Description=qudio After=volumio.service Requires=volumio.service [Service] Type=simple ExecStart=/bin/bash -c 'exec python3.6 /data/INTERNAL/qudio/qudio.py > /tmp/qudio.log 2>&1' User=volumio [Install] WantedBy=multi-user.target
Close the nano editor with Ctrl-X, activate the service and restart the system:
sudo systemctl daemon-reload sudo systemctl enable qudio.service sudo reboot
After rebooting, the player is ready to go. Now you can do a final test with example QR code cards
The QR code on the cards should be about 10×10 mm large with 16 mm padding on top of the card:
While the curb leaves 34 mm space for the card's width, it is a good practice to print the cards with a width of 33 mm. That way they do not get stuck and you can place exactly 9 cards in a line on an A4 sheet.
You can use this ODT template for creating your own cards.
Since the creation of the cards can be a bit of a hassle when the collection grows larger, I have written a card generator for Spotify links. It takes a list of Spotify URIs as input and generates a PDF with the QR codes, the title and the album art. The information is printed both on the front and the back of the cards in order to make sorting of card stacks easier. I will put the generator online as soon as possible.
If you have any questions or improvements please send me an e-mail to email@example.com.