The Circuit Playground can also emulate a USB MIDI drum kit. This will let us play drums using the capacitive touch pads, or anything we hook up to them, like a bunch of fruit. But first, a bit of info on MIDI.

MIDI stands for Musical Instrument Digital Interface and encompasses a whole world of various hardware and software products. For our purposes, we can think in terms of a very simple setup as shown below.

The MIDI PRODUCER generates MIDI SIGNALS which are received by a MIDI CONSUMER that processes the command in the MIDI SIGNAL and takes some kind of action.

For a general overview of the structure of MIDI signals and the commands they contain, check out this episode of Collin's Lab.

For our setup, the Circuit Playground will be the MIDI PRODUCER and a computer will be the MIDI CONSUMER. The MIDI SIGNALS will be transmitted over USB. Software running on the computer will receive and process the MIDI commands.

Since we are going to turn the Circuit Playground into a drum kit, we can use a special set of MIDI commands defined in the General MIDI Specification. These commands use channel 10 to specify percussion (drums) and note numbers 35-81 to specify a specific instrument (kick, snare, hi-hat, etc.). For example, note number 56 is a cowbell.

Ok. Let's put the pieces together.

MIDI USB Library Install

In order to emulate a USB MIDI device, we will use the Arduino Library MIDIUSB. To install it, open up the Library Manager.

Sketch -> Include Library -> Manage Libraries...

Filter the libraries by typing 'midi usb' in the search box in the upper right. Then select the MIDIUSB library and click Install.

MIDI Drum Sketch

Here is the Arduino sketch to turn the Circuit Playground into a USB MIDI drum machine.

// SPDX-FileCopyrightText: 2020 Carter Nelson for Adafruit Industries
// SPDX-License-Identifier: MIT

// Circuit Playground Capacitive Touch USB MIDI Drums
// Send MIDI percussion commands over USB.
// Author: Carter Nelson
// MIT License (

#include <Adafruit_CircuitPlayground.h>
#include "MIDIUSB.h"

#define CAP_THRESHOLD   50
#define DEBOUNCE        100

uint8_t pads[] = {3, 2, 0, 1, 12, 6, 9, 10};
uint8_t numberOfPads = sizeof(pads)/sizeof(uint8_t);

void takeAction(uint8_t pad) {
  Serial.print("PAD "); Serial.print(pad); Serial.print(". Sending MIDI: ");
  switch (pad) {
    case 3:
    case 2:
    case 0:
    case 1:
    case 12:
    case 6:
    case 9:
    case 10:
      Serial.println("THIS SHOULD NEVER HAPPEN.");

boolean capButton(uint8_t pad) {
  // Check if capacitive touch exceeds threshold.
  if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
    return true;  
  } else {
    return false;

void noteOn(byte channel, byte pitch, byte velocity) {
  // Send a MIDI Note On command.
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};

void noteOff(byte channel, byte pitch, byte velocity) {
  // Send a MIDI Note Off command.
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};

void drumHit(byte drum) {
  // Send Note On/Off command for given drum (note) number.
  noteOn(9, drum, 125);
  noteOff(9, drum, 0);

void setup() {
  // Initialize serial.
  // Initialize Circuit Playground library.

void loop() {
  // Loop over every pad.
  for (int i=0; i<numberOfPads; i++) {
    // Check if pad is touched.
    if (capButton(pads[i])) {
      // Do something.
      // But not too often.

Download it and use the Arduino IDE to upload it to the Circuit Playground.

The following was only tested on Linux.

MIDI Drum Machine Software

We will use the software application Hydrogen to receive the MIDI signals from the Circuit Playground and play drum sounds. Downloads are available for Linux, Windows, and OS X.

The Hydrogen application is a full featured drum machine that let's you create drum patterns and full songs. For our simple Circuit Playground drum machine, we will ignore most of the user interface. The drum sounds are shown on the left side of the window and the corresponding Circuit Playground touch pad is shown in the figure below.

To enable the Circuit Playground in the Hydrogen software, first load the above sketch and make sure the Circuit Playground is connected via USB. Now, open the preferences window:

Tools -> Preferences

and select the Midi System tab. In the Input drop down, select the option with Circuit Playground in it. Also, check the Ignore note-off box. Then click OK.

At this point, if you touch one of the pads on the Circuit Playground you should hear a drum sound.

Making the Fruit Drums

Let's connect some fruit! Pretty much anything should work. Just get a bunch of fruit and hook them up using the alligator clips.

The alligator clip can be connected directly to fruit with a stem.

For fruit without a stem, a short jumper wire can be used.

One end of the alligator clip goes to the fruit, the other end to the touch pad on the Circuit Playground.

Once you've got your fruit all connected and arranged, it's time to rock out. The video below shows a brief demo of the Circuit Playground USB MIDI Fruit Drum Machine in action. Note that the Hydrogen app is running on the monitor in the background. The Circuit Playground is attached to the same PC via the USB cable.

This guide was first published on Nov 15, 2016. It was last updated on Nov 15, 2016.

This page (Fruit Drums) was last updated on Nov 11, 2016.

Text editor powered by tinymce.