Introduction: DIY Audiobook Player for Children - Phoniebox

In my childhood I used to have a cassette and later a CD player to listen to music and audiobooks in my room. One of the issues I regularly ran into was scratched CDs or tangled Cassettes. So I wanted something else for my children. Something that is easy and intuitive to use but does not break easy. Extendable and open for change and can grow with my children. Oh and really important. No screen should be involved. Spotify or any other service would be a plus.

I feel locking my self into one system takes away the freedom to choose and you always run the risk of what happens if the company does not exist anymore. This also goes towards the value it offers. Some systems offer audiobooks for kids that are cut and reduced to a minimum and then sold for a high price.

I looked at Toniebox, Hörbert and others that are available in Germany but they all did not full-fill all requirements. Until I found the OpenSource project Phoniebox. It is free, extendable and has an active welcoming community.

By now I have built two Phonieboxes and in the following I want to share my experience setting it up and building an box for it.

Supplies

1x Raspberry Pi 3

1x Micro SD Card

1x USB Powered Speakers

3x Arcade Buttons

1x Push Button with LED light

1x USB RFID ID Card Reader

1x Micro USB 5-Pin Male to Female Extension Panel

1x Rotary Encoder (KY-040)

RFID Cards, Cables, Plugs, Power Supply for Raspberry Pi

Optional

1x Pimoroni ON/OFF Shim for easy power control of Raspberry Pi

1x Ethernet Extension Network Cable

Container/Wood ... as Case

CNC, 3d Printer

Step 1: Prepare Raspberry Pi

Install Operating System

  1. Connect your Micro SD card (through a card reader) to your computer
  2. Download the Raspberry Pi Imager and open it
  3. Select in "Raspberry Pi OS (other)" the "Raspberry Pi OS Lite (Legacy)" (since currently it only Supports Buster)
  4. Select your Micro SD card (your card will be formatted)
  5. Click the gear icon in the bottom right to access the advanced settings (hostname, ssh, username/password, WiFi, Timezone and others)
  6. Once everything is set up click on the Write Button to finalise the image and write it onto the SD Card
  7. Wait for the imaging process to be finished (it can take a few minutes)


First Boot

Login into your Raspberry Pi, default username is pi and default password is raspberry. If raspberrypi.local does not work, find out your Raspberry Pi's IP address from your router.

$ ssh pi@raspberrypi.local

Now it is best practice to update raspberry pi software to the latest available version to get all security updates.

$ sudo apt update && sudo apt full-upgrade

Reboot your raspberry pi.

Login again with SSH and open the Raspberry Pi config.

$ sudo raspi-config

Now we need to update the following settings to allow a fast and issue free start.

1 System Options
S5 Boot / Auto Login -> B2 Console Autologin
S6 Network at Boot -> Yes

No close the panel via the <Finish> and shut down the Pi.

Step 2: Prepare / Test Speakers

Prepare necessary Hardware

  1. Connect the RFID Reader
  2. Plug in the speakers and power them. (Speakers above could be powered via USB of the Raspberry PI)
  3. Boot the Raspberry PI



Test Speakers

I had to learn the hard way. Please do not skip testing the speakers. (Troubleshoot)

$ speaker-test -c2

Step 3: Install Phoniebox

Make sure you have the speakers and RFID card reader plugged into the raspberry pi. It is needed during the setup.

Then run the following command in your SSH terminal and follow the instructions. [source]

cd; rm buster-install-*; wget https://raw.githubusercontent.com/MiczFlor/RPi-Jukebox-RFID/master/scripts/installscripts/buster-install-default.sh; chmod +x buster-install-default.sh; ./buster-install-default.sh

If you want to install including the auto wifi hotspot feature run the following script [source]

cd; rm buster-install-*; wget https://raw.githubusercontent.com/MiczFlor/RPi-Jukebox-RFID/master/scripts/installscripts/buster-install-default-with-autohotspot.sh; chmod +x buster-install-default-with-autohotspot.sh; ./buster-install-default-with-autohotspot.sh


If you followed the instructions above you can choose the following options during the setup.

  1. Yes to Continue interactive installation
  2. No to the Wifi Setting step - it's already set!
  3. Speaker to CONFIGURE AUDIO INTERFACE (iFace)
  4. Yes to CONFIGUREMPD
  5. Yes to FOLDER CONTAINING AUDIO FILES
  6. Yes to Activate GPIO
  7. Yes to Do you want to start the installation?
  8. ... Now you will have to wait a few minutes. Phoniebox will be installed ...
  9. Yes to Have you connected your RFID reader?
  10. 1 to select 1. USB-Reader
  11. Choose the # that matches with your RFID reader
  12. Yes to Would you like to reboot now?



Verify Setup

Now, once the Raspberry Pi rebooted, you can open your Browser and enter http://phoniebox.local or the IP of your PI. This should open the web interface of the Phoniebox.

To verify the connection to the Card Reader is working you can navigate to Card ID and swipe a RFID card on the reader. Now the Last used Chip ID should update in the ui and most likely you will have heard a BEEP noise from the reader.

Step 4: Wiring

Now we need to wire everything up. In my case I decided to use a rotary encoder for as the volume knob but you could also use any other buttons or RFID cards.


Buttons

Pin numbering on Raspberry Pi's always has been very confusing for me. But in Phoniebox it uses the actual GPIO number. For GPIO17 you would use in the config the pin: 17.

Here you can read the extended documentation of Phoniebox to connect your buttons: Using-GPIO-hardware-buttons

In my case I connected the buttons and the rotary encoder as shown in the table (see images of this step). Since I used as power button a button with an integrated LED I connected the GPIO12 to the button as well.

Power On / Shutdown Button

Raspberry PI supports the wake on button press (power on) on GPIO3. This means if you do not use a ON/OFF Shim or similar this would be the GPIO port that you can use to turn on the PI if it is switched off. Phoniebox comes with a shutdown script to avoid any corruption of the SD card.

Volume Control

As volume control in the first box that I built I used two buttons but this seems to not reliably work or sometimes hard to precisely control. This is why I used in version 2 a rotary encoder as the volume knob.

The encoder in the BOM has also the functionality of a click which I configured to be used as mute button.




Important is that all buttons need to be connected with one lead to GND to function properly (can be seen on diagram).

Step 5: Configure Phoniebox

Once the wiring is set up the next step is to configure the phoniebox.

Initially you need to ssh on the Raspberry PI. The default password, which hopefully has been changed already, is raspberry.

$ ssh pi@[address of your pi]


BUTTONS

to configure the buttons and enable the rotary controller you need to adjust the config

$  nano ~/RPi-Jukebox-RFID/settings/gpio_settings.ini

In this file you need to update the pins according to the wiring. There are some sample configs in the Phoniebox Github repository but I also attached the configuration that I used.

[DEFAULT]
enabled : True

[VolumeControl]
enabled : True
type : RotaryEncoder
pin1 : 5
pin2 : 6
timeBase: 0.02
functioncall1 : functionCallVolU
functioncall2 : functionCallVolD

[PrevNextControl]
enabled : True
type : TwoButtonControl
pin1 : 22
pin2 : 23
functioncall1 : functionCallPlayerPrev
functioncall2 : functionCallPlayerNext
functioncalltwobuttons : None
hold_time : 0.3
pull_up_down : pull_up
hold_mode : None

[PlayPause]
enabled : True
type : Button
pin : 27
hold_time : 0.3
functioncall : functionCallPlayerPause
pull_up_down : pull_up

[Shutdown]
enabled : True
type : ShutdownButton
pin : 3
hold_time : 2
functioncall : functionCallShutdown

[StatusLED]
enabled: True
Type: StatusLED
Pin: 12

[Volume0]
enabled : True
type : Button
pin : 17
hold_time : 0.3
functioncall : functionCallVol0
pull_up_down : pull_up

[NextSong]
enabled : False
type : Button
pin : 26
hold_time : 0.3
functioncall : functionCallPlayerNext
pull_up_down : pull_up

[PrevSong]
enabled : False
type : Button
pin : 20
hold_time : 0.3
functioncall : functionCallPlayerPrev
pull_up_down : pull_up

[Halt]
enabled : False
type : Button
pin : 21
hold_time : 0.3
functioncall : functionCallPlayerPauseForce
pull_up_down : pull_up

Step 6: Building the Box

Designed the box initially with Autodesk Fusion360 and then I cut the wood with my Sainsmart ProVer CNC machine.


SIDES

On the sides I inlayed on the inside the speakers and added small holes for the audio to go through. This allowed to glue the speakers into place and reduced the space they needed.

On one side there is another hole that allows adding the power on/off button.


BACK

On the back I added the micro usb port for power and a breakout for the LAN port of the raspberry pi to allow easy access if WiFi is not working. (a learning from version 1 I built)


FRONT

At the front panel I added one single hole for the rotary encoder. The knob initially was just the stock knob but later I 3d printed a knob with GlowInTheDark filament.


TOP

At the top I glued the RFID reader underneath the RFID sign. First I was worried that the signal might not reach through but it works fine. Please be sure to test before hand.

Otherwise I added 3 holes for the arcade buttons for Previous, Play/Pause and Next.


Then the next step was to paint the box. I used acrylic paints and the colour scheme that was decided by my son (looks like a fire truck 🚒). First I needed to apply a primer once that was dry I painted the box in red and inlays in blue. Finally I sprayed the box in clear varnish.

Step 7: Decorating the RFID Cards (optional)

After trying to draw on the cards and me not being a good artist I tried to print out a picture matching the audiobook that is connected to the card. In the first version I just glued it onto the card but unfortunately those pictures did not last long. So next I wanted to try to laminate the cards. This actually worked very well and did not actually melt the cards 😅 Unfortunately by adding a label to the cards it limits a card to only that audiobook and does not allow for easy changing.

Another idea is to use a 3d printer and little rfid tags. This project creates a reusable RFID Tag that is not easy to lose and I can replace the image at any time. https://www.printables.com/model/281928-rfid-tag-case


Step 8: Setup HomeAssistant Control (optional)

Since I have a smart home setup using HomeAssistant I wanted to connect the phonieboxes to it as well. Luckily the project had already support for MQTT which allows easy communication for IoT devices.

To activate MQTT in your phoniebox you need to copy and adjust the service file. This will start a daemon that will take care of the MQTT communication

# navigate to MQTT folder
$ cd ~/RPi-Jukebox-RFID/components/smart-home-automation/MQTT-protocol/

# install missing depenencies
$ sudo python3 -m pip install --upgrade --force-reinstall -q -r requirements.txt

# copy the daemon script and service config file to the correct directory:
sudo cp ./daemon_mqtt_client.py ~/RPi-Jukebox-RFID/scripts/
sudo cp ./phoniebox-mqtt-client.service.stretch-default.sample /etc/systemd/system/phoniebox-mqtt-client.service

As the next step you will need to configure the MQTT client to connect to the correct MQTT server. In the case of HomeAssistant you can start the MQTT server as an addon.

For this you need to navigate in HomeAssistant to Settings > Add-ons and click at the bottom right the ADD-ON STORE button to add a new add-on. In the store you will find the Mosquito broker which is a MQTT Server. Please install and follow the setup wizard/documentation for the broker.

Once the broker is set up you need to use the credentials to configure the phoniebox. For this navigate to the previously copied file and update the SETTINGS section according to the credentials, address and connection settings of your broker.

$ nano ~/RPi-Jukebox-RFID/scripts/daemon_mqtt_client.py


Once configured correctly the service needs to be activated now.

# Initially systemd has to be informed that there's a new service file:
$ sudo systemctl daemon-reload

# Now the service needs to be enabled, to start it on reboot:
$ sudo systemctl enable phoniebox-mqtt-client

# And now you can reboot the phoniebox to have your daemon running or start it manually:
$ sudo systemctl start phoniebox-mqtt-client

# To check the status of the service:
$ sudo systemctl status phoniebox-mqtt-client

# To check the logs. (add -f to follow the latest logs)
$ sudo journalctl -eu phoniebox-mqtt-client


This will be the basic setup for MQTT communication. To actually also use the communication you can use for example this repository that adds the Phoniebox as media player to Home Assistant and handles all the communication for you. This will add a tile like seen in the attached screenshot to your dashboard that allows control of the box.

https://github.com/c0un7-z3r0/hass-phoniebox

To use the Plugin you need to set up HACS on your home assistant. HACS is a Home Assistant Community Extension store. To setup HACS please follow the official documentation: https://hacs.xyz/

Once you set up HACS you can add the the Phoniebox extension as described here: https://github.com/c0un7-z3r0/hass-phoniebox#installation