Hardware Reference
In-Depth Information
Project 32
Fun with MIDI
In this project, you'll see how a binary
protocol is handled by running some basic
MIDI exercises. Because of the wide range
of MIDI controllers and input devices on
the market, MIDI offers a very broad range
of sonic possibilities. So, MIDI is a good
protocol to be familiar with if you like
sound projects.
MATERIALS
» 1 Arduino
» MIDI Musical Instrument shield
» 1 Sharp IR ranger
» 1 100µF capacitor
» 1 pair headphones or speakers
The first sketch below is a test of the available instru-
ments and channels. You'll notice that for each instrument,
channel 10 is percussion—that's also part of the general
MIDI instrument specification. This specification makes it
possible for you to use a controller on the same channel
and instrument with any MIDI synthesizer, and know more
or less what kind of sound you'll get.
The best way to get started with MIDI is to build a very
simple controller, connect it to a synthesizer, and see what
it can do. If you have your own synthesizer, you can use the
circuit in Figure 11-4; if not, you can use the Musical Instru-
ment shield as shown in Figure 11-5. It just stacks on top
of an Arduino like other shields. The synth receives MIDI in
from the Arduino's pin 3. To communicate with it, you'll use
the SoftwareSerial library.
Play It
Start by setting up your
pins, as usual. MIDI out
will be on pin 3, and the Music Instru-
ment shield reset pin is on pin 4. If you're
using an external synth and the circuit
in Figure 11-4, you won't need the reset
connection.
/*
MIDI general instrument demo
Context: Arduino
Plays all the instruments in a General MIDI instrument bank
*/
#include <SoftwareSerial.h>
// set up a software serial port to send MIDI:
SoftwareSerial midi(2,3);
setup() starts the serial and MIDI con-
nection, and resets the shield. Then it
sends a MIDI Control Change command
on channel 0 (0xB0) to perform a Bank
Selection. This sets the bank of instru-
ments you'll play.
const byte resetMIDI = 4; // Midi synth chip reset line
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// initialize MIDI serial on the software serial pins:
midi.begin(31250);
This example is based on Nathan
Seidle's example sketches for the
Musical Instrument Shield, available at
www.sparkfun.com/products/10587 .
//Reset the MIDI synth:
pinMode(resetMIDI, OUTPUT);
digitalWrite(resetMIDI, LOW);
delay(20);
digitalWrite(resetMIDI, HIGH);
delay(20);
// send a MIDI control change to change to the GM sound bank:
sendMidi(0xB0, 0, 0);
}
 
Search WWH ::




Custom Search