Today I am going to show you how to make a Soundboard using Raspberry Pi. A soundboard is a box with a lots of button in it like a Synth box, upon pressing each button it plays a sound or tone or musical note. This can be used for teaching kids different animal sounds, for party purpose or to create a meme box for fun purpose.
Below are my affiliate links to the product used for this project
Female to Female Jumper Cable Wires 20cm
Once you have you required hardware ready you need to start connecting them. Refer here for interfacing the keypad with Raspberrry pi. Now if you have gone thorough the link and connected the keypad, then only thing left is the speaker. I used a 3.5mm jack based speaker, while other may use a HDMI one. I leave it your choice of hardware availability.
$ git clone https://github.com/codelectron/Soundboard
Before starting the application you need to install the dependancies of the application.
pip install pad4pi pip install pygame
Now the application is ready for playing let me explain the source code firstly.
# Setup Keypad
KEYPAD = [
Here the keypad is defined for future reference lookup. whenever key is pressed this array will be looked up and the value will be returned.
ROW_PINS = [11,23,24,25] # BCM numbering
This single dimension array consist of pins connected to the row of the keypad.
COL_PINS = [17,27,22] # BCM numbering
This single dimension array consist of pins connected to the column of the keypad.
This is the pygame mixer initialisation which is required before we start using the mixer for playing tones.
factory = rpi_gpio.KeypadFactory()
This is the template factory object that we need to create in order to make a new keypad.
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
Here we create a keypad handler with the above defined characteristics.
Here we pass the interrupt handler to process key.
#raw_input(“Press Enter to continue…”)
Before we end the application we need to exit the keypad module clean that is done using the cleanup function.
The rest is all condition to decide which tone to play.
This function takes a wav/mp3 file path as parameter and stop the mixer if it is already playing and then load the new file and play it. All what I have written here have been explained by me in this video