Quick Fruit Piano With MIDI

2,399

16

15

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 with the Arduino version.

You need:

  • an Arduino (Mega for 8 keys, Uno for 6 keys) or a black pill STM32F103C8 board ($2 on Aliexpress) plus a UART-to-USB converter (e.g., an Arduino or a CH340)
  • USB cable
  • 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
  • computer.

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 Arduino's audio playback is either via an included python script on the computer or hairless-midiserial.

If you use the STM32F103C8 development board, then it's even nicer: the piano becomes a real USB MIDI controller, without the need for hairless-midiserial.

Note: To prevent damage to the Arduino/STM32F1 from static electricity, especially on a dry day or on carpet, I suggest not touching the aluminum foil or test clips when the device is operating. Instead, touch the fruit, playdough, etc., whose resistance should provide some ESD protection.

Step 1: Arduino Libraries

In the Arduino IDE, choose Sketch | Include Library | Library Manager. Search for my ADCTouchSensor. Install the library.

Then choose File | Examples | ADCTouchSensor | CapacitivePiano.

If you have an Arduino, plug your Arduino into your computer's USB port and upload the CapacitivePiano 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.

If you have an STM32F103C8, first install the bootloader and set up the Arduino IDE for it (with my branch of the addMidiHID branch) by following the first three steps here. Then go back to the Library Manager, and search for my USBHID_stm32f1 library. Install it.

Step 2: Attach Leads to Piano Keys

Run wires from the A0-A7 (A0-A5 on Uno) pins on your Arduino or STM32F103C8 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 or playdough.

Step 3: Install Software: Option A: Arduino and 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: Arduino and 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: Install Software: Option C: STM32F103C and MIDI Synthesizer Software

If you have the STM32F103C, you can use any software that works with a MIDI keyboard controller.

On a computer, I use the Virtual MIDI Piano Keyboard (VMPK). With the STM32F103C plugged in, choose Edit | MIDI Connections | Input MIDI Connection, and then choose Maple MIDI or Diro Synth.

On an Android device, I've successfully used (with a USB OTG cable) Common Analog Synthesizer and Synth DX7 Piano.

Step 6: 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).

If you use the STM32F103C8, then use your favorite MIDI synthesizer software on a computer or mobile device.

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.

Share

    Recommendations

    • Puzzle Challenge

      Puzzle Challenge
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Plastics Contest

      Plastics Contest

    15 Discussions

    0
    None
    SethB62

    6 months ago

    Flashing works with STM32 ST-LINK utility (STSW-LINK004) and ST-Link V2 ($2 on Aliexpress)

    0
    None
    SethB62

    Question 7 months ago

    I find the black pill impossible to flash. I've tired your instructions several times with different hardware. Would I be able to do your project with a STM32F103RET6 development board and a ST-Link JTAG programmer?

    7 more answers
    0
    None
    arprussSethB62

    Answer 6 months ago

    That WAVGAT board has a bad reputation. See discussions on http://stm32duino.com

    The black pill you have should work fine with ST-Link.

    I suggest you post about your flash problems on the stm32duino board. I am not sure how to help you, because I've never had any problems myself with flashing several boards.

    You might try to see if you have successful serial communication with the board. The protocol is described here: http://www.st.com/content/ccc/resource/technical/d...

    If you send 0x00 0xFF, you should be able to get an ACK of 0x79.

    0
    None
    SethB62SethB62

    Answer 6 months ago

    It's white. 9 is going to TX. I also tried this with a USB to TTL, but I returned because I've never got the flashing to work. I guess it could be the black pill board. I'm getting another one soon. I answered my original question, the Library won't compile on STMF103R series. I'm going to order this board and try it out. https://www.aliexpress.com/item/WAVGAT-STM32F103C8... it should work with the boot20_pc13.bin It has a ST-LINK connector, hopefully that makes flashing and debugging easier.

    0
    None
    arprussSethB62

    Answer 6 months ago

    Looking at your photo, you have a gray wire going to A9, but a white wire on the UNO's TX line, so the connection doesn't look right.

    0
    None
    SethB62SethB62

    Answer 7 months ago

    After selecting the correct Com Port. "No response from the target, the boot loader can not be started." I followed hook up and flash instructions in $3 Makey Makey instructions exactly.

    3dollar.jpgflash.jpg
    0
    None
    arprussSethB62

    Answer 7 months ago

    That pill looks right. What are you using for your serial to USB adapter? What messages do you get in the STM FlashLoader?

    0
    None
    SethB62SethB62

    Answer 7 months ago

    Here a Picture of a Black Pill. I have another one on the way. I'll try that one too.

    BlackPill.jpg
    0
    None
    arprussSethB62

    Answer 7 months ago

    Can you post a photo of your black pill? There are some black boards that are actually just a re-colored blue pill.

    0
    None
    yamnitram

    9 months ago

    Thank You. Excellent Instructable.
    Used blue pill (STM32F103C8), PC13 for LED in code, PA0 to PA7 for "keys" and PA8 pin grounded. Headers were soldered in and female to male dupont jumpers with male end stuck into potatoes, carrots, onions, apples and oranges for variety. Couldn't get the midi to work with win 10 and serial port also failed when sketch uploaded to board so had to wipe to recover control of board using st-link. Worked no problem on an Android device, with a USB OTG cable. Maybe you could highlight this as option D in your instructable as it works very well. Thank you. Children love it, both my own and those in our village playgroup. I have really enjoyed getting it working.

    2 replies
    0
    None
    arprussyamnitram

    Reply 9 months ago

    The current version of the USBHID library doesn't build in serial support by default. You can add it by changing USBHID.begin() to USBHID_begin_with_serial() in the code. But you also don't need serial to upload: just press the reset button at the right point during the upload process.

    I've fixed some things with the USBHID library. Check if the current version works with MIDI for you.

    0
    None
    yamnitramarpruss

    Reply 8 months ago

    Got the hang of the reset button upload so that is working fine. Have also updated the USBHID library and is still working as expected.

    Sorry for slow response. Complete computer failure at home so had to rebuild everything.

    Thank you for your advice. Much appreciated. Have shown to a couple of primary school teachers and they love it too.

    This is always a great introduction to electronics project for kids.