FIGURE 8. Recommended hookup for
connecting the output of any VLSI VS10xx-
based MIDI sound module with an external
amplifier. This is from the manufacturer's
datasheet. Only one stereo side is shown
connected.
set the value. The three most common
control change messages – and the ones
used in the example sketches – are:
Option
Bank Select
Channel Volume
All Notes Off
Control Byte
0x00
0x07
0x7B
Examples:
0xB0|0 0x00 0x78
0xB0|5 0x07 63
0xB0|3 0x7B 0
// Sets bank 0x78 (decimal
// 120) on channel 0
// Sets volume to 63 on
// channel 5
// Turns off all notes
// playing on channel 3
• Reset. This pin provides a method of resetting the MIDI
chip on the sound board to a known state. Do this after
the board has been powered up, but before sending any
MIDI data. Resetting is accomplished by momentarily
bringing the pin LOW, then HIGH again.
Figure 8 shows the basic wiring points between the
Arduino and MIDI board. If you’re using a shield, the
Connecting a
MIDI Sound
Module to
the Arduino
LISTING 1 - MIDI_VerySimple.ino
// Rx, Tx (Rx not used, Tx pin=3)
Thanks to the “maker
movement” there are now a
number of affordable MIDI sound
modules available for the Arduino
and other microcontrollers. Figure
6 shows a MIDI sound module
shield from SparkFun, designed
for the Arduino Uno (and
compatible) development board.
Variations include shields that
combine MIDI with MP3 playback,
as well as breakout boards that
provide additional connection pins
for more advanced hookups.
Figure 7 shows both of these
styles (also from SparkFun). The
MIDI/MP3 shield includes an
onboard micro-SD card reader that
provides storage for the sound files.
Despite all the pins on these
boards, most modules require only
a couple of connections for MIDI
operation:
void setup() {
MIDI.begin(31250);
resetMidi(4);
ctrlMIDI(0, 0x07, 127);
ctrlMIDI(0, 0x00, 0x79);
sendMIDI(0xC0|0, 0, 0);
}
// Set up serial comm to MIDI
// Reset MIDI device (pin 8)
// Set channel volume (0-127) to full
// Select 'melodic' bank
// Select instrument in bank
void loop() {
noteOn(0, 60, 127);
delay(1000);
noteOff(0, 60, 127);
delay(1000);
}
// Turn on middle-C note, velocity=127
// Wait one second
// Turn off note
// Turn note on (press key)
void noteOn(byte channel, byte note, byte attackVelo) {
sendMIDI( (0x90 | channel), note, attackVelo);
}
// Turn note off (release key)
void noteOff(byte channel, byte note, byte releaseVelo) {
sendMIDI( (0x80 | channel), note, releaseVelo);
}
// Set controller value with channel
void ctrlMIDI(byte channel, byte data1, byte data2) {
sendMIDI( (0xB0 | channel), data1, data2);
}
// Send bytes to MIDI device
void sendMIDI(byte cmd, byte data1, byte data2) {
MIDI.write(cmd);
MIDI.write(data1);
// Pass only if valid 2nd byte
if( (cmd & 0xF0) <= 0xB0 || (cmd & 0xF0) == 0xE0 )
MIDI.write(data2);
• MIDI input. This pin accepts
asynchronous serial at a specific
baud rate of 31250 bits per
second. Use the Arduino
SoftwareSerial object library to
transmit serial data directly to
the board.
}
// Reset MIDI device
void resetMidi(int resetPin) {
pinMode(resetPin, OUTPUT);
digitalWrite(resetPin, LOW);
delay(100);
digitalWrite(resetPin, HIGH);
delay(100);
SERVO 04.2012 57