Introduction: Quick Fruit Piano With MIDI
This is a really simple capacitive-touch piano. Tap on fruit, cans of soda, bottles of water, strips of aluminum foil, etc., and you get polyphonic piano music from your computer. Now that the software is written, the project shouldn't take more than 10 minutes to put together.
- an Arduino (Mega for 8 keys, Uno for 6 keys).
- some aluminum foil
- test clips ideally, but jumpers and paperclips will do (idea for that from here)
- fruit, or playdough, or pieces of paper with areas colored with a pencil
No additional components needed, as this uses code from martin2250's brilliant ADCTouch library and the Arduino sends MIDI commands over serial to the computer. The audio playback is either via an included python script on the computer or hairless-midiserial.
Step 1: Arduino Firmware
Download the ADCTouchSensor library (the zip file will do) and put the contents in Arduino/libraries/ADCTouch directory.
Download the Capacitive Piano sketch and put the contents in Arduino/CapacitivePiano.
Plug your Arduino into your computer's USB port and upload the Capacitive Piano sketch to your Uno or Mega.
The sketch will send data to the computer via USB serial as to which of the 8 (Mega) or 6 (Uno) capacitive sensors was triggered.
Step 2: Attach Leads to Piano Keys
Run wires from the A0-A7 (A0-A5 on Uno) pins on your Arduino to whatever you want to function as piano keys. For instance, I used jumpers with alligator clips or test clips going to pieces of aluminum foil on each of which I put either a can of soda or an orange as the key. The aluminum foil can be used as a key directly. Or one can stick a wire into a piece of fruit or vegetable.
Step 3: Install Software: Option A: Hairless MIDI to Serial Bridge
You can download and install the Hairless MIDI to Serial Bridge (Win/OSX/Linux) to link the Arduino's USB-serial output with your computer's synthesizer software.
If you have Windows 7 or newer, you can use the built-in Microsoft Wavetable GS Synth, so all you need to install is Hairless. Some other playback software will require loopMIDI.
On other systems, you may need a MIDI synthesizer like VirtualMidiSynth or Garageband. You can also use VirtualMidiSynth on Windows if you like.
Step 4: Install Software: Option B: Python
You can also just use a simple included Python script that plays back MIDI notes.
Make sure you have Python installed on your computer. Either 2.7 or 3.x will do.
Make sure you have the pygame Python package installed. If not, run this from the commandline:
python -m pip install pygame
Find out what address your Arduino's serial port is. Your Arduino IDE will have the serial ports listed under Tools | Port.
In the CapacitivePiano package that you downloaded, you will find the music.py script that is the PC side of the project.
Step 5: Play!
Plug the Arduino with the CapacitivePiano sketch into the computer. Do not touch any of the "buttons" until only the power LED is run, to allow the capacitive buttons to be calibrated.
For the Hairless option, run the Hairless MIDI bridge, choose the serial port from the dropdown list. Then choose a synthesizer. On Windows, if you choose Microsoft Wavetable GS Synth, everything should just work.
If you want to use the Python script instead, make sure you are in the directory where you have piano.py, and run:
python piano.py serialport
where serialport is the serial port from Arduino IDE (e.g., COMx on Windows).
Now press your "buttons" and have fun!
Educational ideas for kids to experiment with:
- Experiment with different items on the aluminum foil and see which ones work and which one's don't--and then talk about why these work and others don't.
- Playdough works really well (and then you don't even need foil and clips--you can just stick wires into the playdough, though admittedly it looks like a bomb!).
- You can even take a piece of paper and shade in areas with a pencil (it doesn't have to super dark, but cross-hatching is good) and clip those in.
- You can attach an alligator clip to a really large metal item, like the rim of whiteboard, and make giant keys.
- An experiment to try is to have a smaller person hold an alligator clip attached to one of the wires, and then have a larger person shake hands with or high-five the smaller person, and see if that registers. Then try again with a larger person holding it and a smaller one touching them.
Just make sure that after each change of what is attached to the Arduino, you reset the Arduino, either by pressing the "reset" button or by replugging the USB connection (and then re-run the python code, as it will probably crash), in order to recalibrate the sensors.
One can discuss electrical capacity and capacitive sensing.