A Soundboard for Raspberry Pi.
- What is the purpose of this tool?
- How does it work?
- Build
- Prerequisites
- Build and run soundboard container
- Recommendations
- Configuration
- Testing
- Troubleshoot
- Todo
This tool enables your Raspberry Pi to play a specific sound-file by pressing a
button connected via GPIO.
Depending on the number of buttons to use, the soundboard creates listeners
for the GPIO pins. If a button is pushed the associated sound-file will be played.
During playback no inputs from push buttons will be accepted.
Linux (Raspbian)
Install needed Debian packages:
sudo apt-get install build-essential libasound2-dev alsa-utils
Get dependencies:
go get -u github.com/hajimehoshi/oto
go get -u github.com/faiface/beep
go get -u github.com/micha37-martins/gpio
- Raspberry PI 3 (other versions should also work but I did not test them)
- SD Card
- Power supply
- Wiring
- Pushbuttons
- A suitable case for a soundboard
- An output device like a speaker
It is expected to have a Pull-Up-Resistor
for every push button connected. The resistor should have between 10 and 100 kΩ.
- I tested with Raspbian but other operating systems should also work
- golang 1.14+
make
Older software versions may also work, but I did not test that.
- .mp3 files have to be stored in ./soundfiles folder
- the .gitignore file in this folder have to be removed
To install Docker on a raspberry pi you basically need:
curl -sSL https://get.docker.com | sh
And after the command finished you most likely want to run:
sudo usermod -aG docker pi
Source: Docker install guide
Find your sound device by using
aplay -l
Use environment variable to set your desired sound device
examples:
ALSA_CARD=PCH
ALSA_CARD=HDMI
ALSA_CARD=0
Build container
docker build -t soundboard .
Run container
docker run -it --rm --device /dev/snd -e "ALSA_CARD=SET_YOUR_SOUND_DEVICE" -v /sys:/sys soundboard:0.0.1 /bin/sh
Play test sound:
speaker-test
Example:
docker run -it --rm --device /dev/snd -e "ALSA_CARD=0" -v /sys:/sys soundboard:0.0.1 /bin/sh
You can also use docker-compose to run the soundboard container. The sound_device
you discovered using aplay -l
can be configured in the .env
file. The default
is "PCH".
docker-compose up --build
The --build
flag is needed at first start only.
Configuration is done in /internal/config/config.go
Here the mapping between file and pin is set. The FileMapper
function assigns a filename to the corresponding button. The button
number has to be a two digit string:
For example: "01" for your first button
The pin number for Raspberry Pi 2/3/4 can be found at
raspberrypi.org
Example: Map pin 5 to file 01
ButtonMap[5] = "01"
The number of entries in ButtonMap
have to equal the number of soundfiles.
A usual go test is configured in the Makefile
but it will not do an integration test. If you want to check if the soundboard plays a file use:
go test -tags=integration
- "No files in folder: ./soundfiles/"
- Remove the hidden
.gitignore
file from the./soundfiles
folder
- Remove the hidden
- "failed to open gpio 13 direction file for writing"
- use sudo to run soundboard
- e.g.
sudo /usr/local/go/bin/go run cmd/main.go
- Cannot play sound when using a Docker container
- mount the
/sys
directory to have acess to gpio file - select the correct sound_card
- mount the
- write a soundboard.service example to document how to start soundboard using Systemd