Simple jukebox with Raspberry Pi.
My 3 y.o. kid likes to listen to music, but I couldn't find music player with easy enough UI for her to operate by herself. Interestingly there is no plug-and-play projects/solution to this. So, following the DIYer mantra:
How hard can it be?
User's parent provides audio files (mp3
) in a default location. The files will
be mapped to each button wired to the Raspberry Pi's GPIO input. Button press
will trigger play/stop of the audio file.
This is a home project, code is shit.
sudo apt install gpiozero python3-vlc vlc-bin vlc-plugin-base python3-rpi.gpio
- ALSA volume defaults to 50%, crank it up with
alsamixer
. This is persistent.
- Raspberry Pi 1 (2011).
- Raspbian v10 (Buster) (
cat /etc/os-release
) python3-vlc
v3.0.4106
- Get a Raspberry Pi
- Get a speaker/speaker system that works with Raspberry Pi, and test audio
playback with e.g.
omxplayer
- Get push buttons with LEDs and wire them properly with resistors
- Use
gpio readall
andpinout
to find out pin numbering (see "Useful Development Tools" below) - Configure the BCM pin numbering for the buttons and LEDs(from
gpio readall
) in config file$HOME/.config/pi_jukebox/pi_jukebox.conf
(file created after first run)
Here's how the internal looks like on my setup:
Bottom right is a USB-powered speaker. TODO: cable management
TODO: Draw up wiring diagram
pip3 install git+ssh://git@gitlab.com/bagong/pi_jukebox#egg=pi_jukebox
Run pi_jukebox
to populate initial settings.
- Put mp3 files into to default location:
$HOME/pi_jukebox/
- Music location is configurable in
$HOME/.config/pi_jukebox/pi_jukebox.conf
- Start jukebox:
pi_jukebox
- or make it autostart with adding this entry to
/etc/rc.local
beforeexit 0
su pi -lc "pi_jukebox > /dev/null 2>&1"
- For some reason
gpiozero
'swhen_pressed()
doesn't register button press properly, events are often missed. OlderRPi.GPIO
(v0.7) works much better and reliable.
pinout
command fromgpiozero
packagegpio readall
fromwiringpi
package, to get GPIO readings. Call withwatch -n 0.1 gpio readall
to do 10Hz polling read.