The Raspberry Pi is a single-board computer that is popular in the developer world for its low cost and reliable performance. It can replace your bulky desktop or serve as the brain for your latest robotics project! Pi Hats were created by Adafruit as add-ons to your RPi. For example, their Capacitive Touch Pi Hat adds 12(!!) easy-to-use touch sensors to your RPi, all in a single board. This tutorial teaches you how to use these two products to make your own “piano” out of fruits or vegetables (or any electrodes you want).
PS: If you want to watch the video version of this tutorial instead, you can check it out at our Youtube channel or at our Facebook page. For this tutorial, we highly recommend you check out the video as well so that you can hear the sounds at work! Subscribe to get the latest news and tutorials as they come out! 😀
STEP 1. It’s easier to work if you’ve got all the materials near you! For the non-edible materials, you will need a Raspberry Pi (we used the RPi 3, which already has a built-in WiFi chip), a micro SD card with OS for your RPi already installed, a Capacitive Touch Pi Hat, speakers, your laptop, and a lot of alligator clips!
You will also need electrodes to serve as your “piano keys.” We tried using fruits, vegetables, and some foil, and they all worked out well! You can try random things from you house and see if they work!
STEP 2. Next, follow the wiring diagram below and power up your RPi.
STEP 3. Now we can start programming! First, we need install Putty, an SSH client, which we will use to connect to our RPi. Once Putty is installed, you can choose SSH and input your RPi’s IP address. There are multiple ways you can do this. One is using nmap, and another – which we think is easier- is using an app (we used Fing). Now you can start your Putty session!
STEP 4. A new window will open and ask you for your username and password. If it’s your first time using the RPi, the default username is pi and the default password is raspberry. If you’re a veteran and you’ve changed your username and password before, we hope you remember what it is 😀
STEP 5. Our next step is to install the libraries for the Pi Hat from Adafruit’s Github page. You can execute the following commands in the terminal to do that:
THE VERY IMPORTANT STEP 6. You must enable I2C on your RPi for the codes to work. On your terminal, type sudo raspi-config, then choose Advanced Options > I2C > Yes
STEP 7. Now we’re good to go! Run “playtest.py” from the examples folder of the Adafruit_Python_MPR121 library. If all goes well, the onboard LED of the Pi Hat should light up when you touch the sensors.
STEP 8. Connect your electrodes to the Pi Hat using the alligator clips. Now you can make music (or noise, like in our case :D) with your makeshift “piano!” Just a few more reminders:
a. You might have to change the default sounds for each touch sensor in the python code. You can look for mp3 files already in your RPi, or use a USB to add more tunes to your piano.
b. If the onboard LED lights up when you touch your finger directly to the contacts but doesn’t when you connect the alligator clips and the electrodes, there might be a threshold problem. Check out the threshold property in the Adafruit_Python_MPR121 library.
c. Make sure your speakers are on. 😀
Hooray! We hope this tutorial was helpful for you. If you want to try it out yourself (of course you do, it’s so cool! :D), or if you’re just interested in trying out the RPi3 or any of its accessories like the Pi Hat, we’ve got you covered!