The Music Box is a project that allows you to control a music player using RFID tags. By placing figures on the box, you can start playing the associated song, playlist or audio book. The playback is automatically stopped when removing the figure, providing a toddler-proof interface. You can find more information in the following article: Please tell me more about Music Box
- Control music playback using RFID-tagged figures
- Automatically start and stop playback when adding or removing figures
- Connect to a Bluetooth speaker for audio output
- Configurable through a local web interface
- Supports custom 3D printed figures
The Music Box project uses a Bluetooth speaker to play the audio. When an RFID-tagged figure is placed on the box, the associated song, playlist or audio book starts playing. Removing the figure stops the playback automatically. The project includes a local web interface for configuration, content and tag management, as well as additional playback controls. The interface is designed as a single-page application (SPA) for a smooth user experience. Users can create custom 3D printed figures and associate them with audio content. The figures contain an RFID tag that is detected by the Music Box, allowing for easy and intuitive interaction. Content management, configuration and additional play controls are provided via a web interface running on port 18080.
A settings file in the root is used to store persistent settings. At the moment it is just used for the Bluetooth speaker device path:
{
"speaker": "/org/bluez/hci0/dev_88_C6_26_57_95_B9"
}
systemctl --user start pulseaudio
bluetoothctl
>> scan on
bring speaker into pair mode and wait for it to show up find the 48bit MAC address.
>> pair XX:XX:XX:XX:XX:XX
>> trust XX:XX:XX:XX:XX:XX
>> connect XX:XX:XX:XX:XX:XX
- Stop the service
systemctl --user stop musicbox
- Copy the new executable into the user directory of user "music"
- Grant the executable CAP_SYS_RAWIO capability to perform I/O operations in user context
sudo setcap cap_sys_rawio+ep MusicBox
- Start the service
systemctl --user start musicbox
Prerequisite: Rasberry Pi OS with Wifi enabled and "music" as standard user with sudo permissions.
-
Boot Config
sudo nano /boot/config.txt
add in [all] section
device_tree_param=spi=on dtoverlay=spi-bcm2708 dtparam=act_led_trigger=none dtparam=act_led_activelow=on
change
dtparam=audio=on
todtparam=audio=off
.These settings are for the RFID reader, to turn off the onboard LEDs and deactivate onboard sound to use the pins for controlling the LED ring.
-
Enable SPI
sudo raspi-config
activate "Interface Options" > "SPI"
-
Install some additional packages
sudo apt install pulseaudio-module-bluetooth libcap2
-
Assign some additional groups for the "music" user
sudo usermod -a -G sudo music sudo usermod -a -G bluetooth music sudo usermod -a -G gpio music sudo usermod -a -G spi music sudo usermod -a -G kmem music sudo usermod -a -G video music
-
Udev rule for allowing memory access as non-root user (for the RFID reader)
echo 'SUBSYSTEM=="mem", KERNEL=="mem", GROUP="kmem", MODE="0660"' | sudo tee /etc/udev/rules.d/98-mem.rules
-
Enable auto start of the app in user mode
loginctl enable-linger music mkdir ~/.config/systemd/user cp ~/app/source/service/musicbox.service ~/.config/systemd/user/ systemctl --user enable musicbox.service
-
Enable and configure Pulse Audio
sudo nano /usr/lib/systemd/user/pulseaudio.service
#Restart=on-failure Restart=always
systemctl --user enable pulseaudio
Prerequisites
- Node.js and npm installed on your system
npm install
To build the web root call the following command in /webroot
npm run build
copy /webroot/dist
to the Raspberry Pi ~/webroot
If you would like to contribute to the Music Box project, please feel free to submit issues or pull requests on the GitHub repository. Contributions are welcome for features, bug fixes, documentation, and more.
MusicBox is built using great open source projects including ....
- RPi-RFID
- BCM2835
- rpi_ws281x
- CrowCpp
- nlohmann_json
- libmpg123-0
- libsdbus-c++0
- libcap2
- pulse audio