MIDI Over USB

Adding the Teensy code to your Arduino environment allows you to use the excellent MIDI over USB commands in your sketches. 

You can transmit MIDI messages from your Circuit Playground using a few different commands. (Here's more detailed info from the PJRC Teensy page.) For our needs, the most commons ones are:

 

Download: file
usbMIDI.sendNoteOn(note, velocity, channel)
usbMIDI.sendNoteOff(note, velocity, channel)
usbMIDI.sendControlChange(control, value, channel)

You can test out a basic sketch to see if things are all working.

Download: file
#include <Adafruit_CircuitPlayground.h>

void setup() {
  CircuitPlayground.begin();
}

void loop() {
  /************* TEST BOTH BUTTONS */
  if (CircuitPlayground.leftButton()) {
    CircuitPlayground.redLED(HIGH);
    usbMIDI.sendNoteOn(60, 127, 0);  // 60 = C4 velocity 127 (max)
    delay(100);
    usbMIDI.sendNoteOff(60, 0, 0);
    CircuitPlayground.redLED(LOW);
  }
  if (CircuitPlayground.rightButton()) {
    CircuitPlayground.redLED(HIGH);
    usbMIDI.sendNoteOn(61, 127, 0);
    delay(100);
    usbMIDI.sendNoteOff(61, 0, 0);
    CircuitPlayground.redLED(LOW); 
  }

  // dont listen to any incoming MIDI!
  while (usbMIDI.read()) {
  }
}

Copy that code into your Arduino IDE and then upload it to the Circuit Playground (TeensyCore). Make sure you are in MIDI mode (Tools > USB type > MIDI) and have the correct port selected for your Circuit Playground.

Once uploaded, launch your MIDI monitor software and a music application such as Garage Band. When you press the left and right buttons on the Circuit Playground you should hear see the C4 note indicated in the data stream and hear a C.

This guide was first published on Sep 25, 2016. It was last updated on Sep 25, 2016.

This page (PZ-1 Pizza Box DJ Code) was last updated on Jan 12, 2021.