Tutorial.Midi History

Hide minor edits - Show changes to output

May 02, 2012, at 04:08 PM by Scott Fitzgerald -
Changed line 50 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/04.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
November 16, 2011, at 04:15 AM by Scott Fitzgerald -
Changed line 50 from:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
September 30, 2011, at 03:16 AM by Scott Fitzgerald -
Changed line 50 from:
(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
September 24, 2011, at 01:14 AM by Tom Igoe -
Changed lines 1-34 from:
[[Reference/SerialEvent]]

!!serialEvent()

!!!!Description

Called when data is available. Use Serial.read() to capture this data. The serialEvent() can be set with Serial.buffer() to only trigger after a certain number of data elements are read and can be set with Serial.bufferUntil() to only trigger after a specific character is read.

!!!!Syntax
(:source lang=arduino tabwidth=4:)

void serialEvent(){
//statements
}
(:sourceend:)

''Arduino Mega only:''
(:source lang=arduino tabwidth=4:)
void serialEvent1(){
//statements
}

void serialEvent2(){
//statements
}

void serialEvent3(){
//statements
}
(:sourceend:)

!!!!Parameters

statements: any valid statements
to:
''Examples > Communication''

!!!MIDI Note Player

This tutorial shows how to play MIDI notes from an Arduino.

[[http://en.wikipedia.org/wiki/MIDI|MIDI]], the Musical Instrument Digital Interface, is a useful protocol for controlling synthesizers, sequencers, and other musical devices. MIDI devices are generally grouped in to two broad classes: controllers (i.e. devices that generate MIDI signals based on human actions) and synthesizers (including samplers, sequencers, and so forth). The latter take MIDI data in and make sound, light, or some other effect.

MIDI is a serial protocol that operates at 31,250 bits per second. The Arduino's built-in serial port (all of them on the Mega as well) can send data at that rate.

MIDI bytes are divided into two types: '''command bytes''' and '''data bytes'''. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, and amount of pitch bend, and so forth. For more details, see the MIDI specification, or one of the many [[http://hinton-instruments.co.uk/reference/midi/protocol/index.htm|MIDI Protocol Guides]] on the Web.

MIDI data is usually notated in hexadecimal because MIDI banks and instruments are grouped in groups of 16.

For more see this [[http://www.tigoe.net/pcomp/code/communication/midi | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]].

'''Hardware Required'''
* Arduino Board
* (1) MIDI jack
* (1) 220 ohm resistor
* hook-up wire
* MIDI enabled device ''(optional, for testing)''

!!!Circuit

All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:

* Arduino digital pin 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor


click the image to enlarge

%width=400px%[[Attach:MIDI_bb.png | Attach:MIDI_bb.png]]

[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]


'''Schematic'''

click the image to enlarge

%width=400px%[[Attach:MIDI_schem.png | Attach:MIDI_schem.png]]


!!!Code
(:div class=code :)

(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)

(:divend:)

'''See Also:'''

* [[Serial/begin | @@serial.begin()@@ ]]
* [[Reference/For | @@for()@@ loop]]

* [[Tutorial/SerialCallResponse | Serial Call Response]] - send multiple variables using a call and response (handshaking) method.
* [[Tutorial/ForLoop | For Loop]]: - controlling multiple LEDs with a for loop.
* [[Tutorial/ASCIITable | ASCII Table]]: - generates a table of characters and their ASCII, hexadecimal, octal, and binary equivalents.
September 24, 2011, at 01:11 AM by Tom Igoe -
Changed lines 1-61 from:
''Examples > Communication''

!!!MIDI Note Player

This tutorial shows how to play MIDI notes from an Arduino.

[[http://en.wikipedia.org/wiki/MIDI|MIDI]], the Musical Instrument Digital Interface, is a useful protocol for controlling synthesizers, sequencers, and other musical devices. MIDI devices are generally grouped in to two broad classes: controllers (i.e. devices that generate MIDI signals based on human actions) and synthesizers (including samplers, sequencers, and so forth). The latter take MIDI data in and make sound, light, or some other effect.

MIDI is a serial protocol that operates at 31,250 bits per second. The Arduino's built-in serial port (all of them on the Mega as well) can send data at that rate.

MIDI bytes are divided into two types: '''command bytes''' and '''data bytes'''. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, and amount of pitch bend, and so forth. For more details, see the MIDI specification, or one of the many [[http://hinton-instruments.co.uk/reference/midi/protocol/index.htm|MIDI Protocol Guides]] on the Web.

MIDI data is usually notated in hexadecimal because MIDI banks and instruments are grouped in groups of 16.

For more see this [[http://www.tigoe.net/pcomp/code/communication/midi | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]].

'''Hardware Required'''
* Arduino Board
* (1) MIDI jack
* (1) 220 ohm resistor
* hook-up wire
* MIDI enabled device ''(optional, for testing)''

!!!Circuit

All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:

* Arduino digital pin 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor


click the image to enlarge

%width=400px%[[Attach:MIDI_bb.png | Attach:MIDI_bb.png]]

[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]


'''Schematic'''

click the image to enlarge

%width=400px%[[Attach:MIDI_schem.png | Attach:MIDI_schem.png]]


!!!Code
(:div class=code :)

(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)

(:divend:)

'''See Also:'''

* [[Serial/begin | @@serial.begin()@@ ]]
* [[Reference/For | @@for()@@ loop]]

* [[Tutorial/SerialCallResponse | Serial Call Response]] - send multiple variables using a call and response (handshaking) method.
* [[Tutorial/ForLoop | For Loop]]: - controlling multiple LEDs with a for loop.
* [[Tutorial/ASCIITable | ASCII Table]]: - generates a table of characters and their ASCII, hexadecimal, octal, and binary equivalents.
to:
[[Reference/SerialEvent]]

!!serialEvent()

!!!!Description

Called when data is available. Use Serial.read() to capture this data. The serialEvent() can be set with Serial.buffer() to only trigger after a certain number of data elements are read and can be set with Serial.bufferUntil() to only trigger after a specific character is read.

!!!!Syntax
(:source lang=arduino tabwidth=4:)

void serialEvent(){
//statements
}
(:sourceend:)

''Arduino Mega only:''
(:source lang=arduino tabwidth=4:)
void serialEvent1(){
//statements
}

void serialEvent2(){
//statements
}

void serialEvent3(){
//statements
}
(:sourceend:)

!!!!Parameters

statements: any valid statements
September 24, 2011, at 01:05 AM by Tom Igoe -
August 02, 2011, at 09:18 AM by Davide Gomba -
Changed line 50 from:
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
to:
(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
September 23, 2010, at 10:36 PM by Christian Cerrito -
Changed lines 3-4 from:
!!MIDI Note Player
to:
!!!MIDI Note Player
September 16, 2010, at 10:15 PM by Tom Igoe -
Changed line 50 from:
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4 border=0:)
to:
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
September 16, 2010, at 10:15 PM by Tom Igoe -
Changed line 50 from:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde border=0:)
to:
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4 border=0:)
September 16, 2010, at 02:25 AM by Christian Cerrito -
Changed lines 57-61 from:
* [[Serial/read| @@serial.read()@@]]
* [[Reference/SwitchCase| @@switch() case@@]]
* [[Tutorial/ifStatement | @@if()@@ statement]]
* [[Reference/digitalWrite | @@digitalWrite()@@]]
to:
* [[Reference/For | @@for()@@ loop]]
Deleted lines 59-60:
* [[Tutorial/SerialCallResponseASCII | Serial Call and Response ASCII]] - send multiple vairables using a call-and-response (handshaking) method, and ASCII-encoding the values before sending.
* [[Tutorial/IfStatement | If Statement]] - how to use an if statement to change output conditions based on changing input conditions.
Deleted lines 60-70:
* [[Tutorial/Array]]: a variation on the For Loop example that demonstrates how to use an array.
* [[Tutorial/While Loop]]: how to use a while loop to calibrate a sensor while a button is being read.
* [[Tutorial/Switch Case]]: how to choose between a discrete number of values. Equivalent to multiple If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.

'''See Also:'''

* [[Serial/begin | @@serial.begin()@@ ]]
* [[Reference/For | @@for()@@ loop]]

* [[Tutorial/SerialCallResponse | Serial Call Response]] - send multiple variables using a call and response (handshaking) method.
* [[Tutorial/ForLoop | For Loop]]: - controlling multiple LEDs with a for loop.
September 16, 2010, at 02:24 AM by Christian Cerrito -
Changed lines 52-77 from:
(:divend:)
to:
(:divend:)

'''See Also:'''

* [[Serial/begin | @@serial.begin()@@ ]]
* [[Serial/read| @@serial.read()@@]]
* [[Reference/SwitchCase| @@switch() case@@]]
* [[Tutorial/ifStatement | @@if()@@ statement]]
* [[Reference/digitalWrite | @@digitalWrite()@@]]

* [[Tutorial/SerialCallResponse | Serial Call Response]] - send multiple variables using a call and response (handshaking) method.
* [[Tutorial/SerialCallResponseASCII | Serial Call and Response ASCII]] - send multiple vairables using a call-and-response (handshaking) method, and ASCII-encoding the values before sending.
* [[Tutorial/IfStatement | If Statement]] - how to use an if statement to change output conditions based on changing input conditions.
* [[Tutorial/ForLoop | For Loop]]: - controlling multiple LEDs with a for loop.
* [[Tutorial/Array]]: a variation on the For Loop example that demonstrates how to use an array.
* [[Tutorial/While Loop]]: how to use a while loop to calibrate a sensor while a button is being read.
* [[Tutorial/Switch Case]]: how to choose between a discrete number of values. Equivalent to multiple If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.

'''See Also:'''

* [[Serial/begin | @@serial.begin()@@ ]]
* [[Reference/For | @@for()@@ loop]]

* [[Tutorial/SerialCallResponse | Serial Call Response]] - send multiple variables using a call and response (handshaking) method.
* [[Tutorial/ForLoop | For Loop]]: - controlling multiple LEDs with a for loop.
* [[Tutorial/ASCIITable | ASCII Table]]: - generates a table of characters and their ASCII, hexadecimal, octal, and binary equivalents.
September 16, 2010, at 02:06 AM by Christian Cerrito -
Changed line 19 from:
* MIDI Connector
to:
* (1) MIDI jack
Changed line 28 from:
* digital in 1 connected to MIDI jack pin 5
to:
* Arduino digital pin 1 connected to MIDI jack pin 5
September 16, 2010, at 02:05 AM by Christian Cerrito -
Changed lines 22-23 from:
* MIDI enabled device "(optional, for testing)"
to:
* MIDI enabled device ''(optional, for testing)''
September 16, 2010, at 02:04 AM by Christian Cerrito -
Deleted line 8:
Deleted line 14:
Added lines 17-23:
'''Hardware Required'''
* Arduino Board
* MIDI Connector
* (1) 220 ohm resistor
* hook-up wire
* MIDI enabled device "(optional, for testing)"
September 16, 2010, at 01:58 AM by Christian Cerrito -
Changed lines 17-18 from:
For more see this [[http://www.tigoe.net/pcomp/midi.shtml | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]].
to:
For more see this [[http://www.tigoe.net/pcomp/code/communication/midi | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]].
September 16, 2010, at 01:56 AM by Christian Cerrito -
Changed line 45 from:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/Midi.pde border=0:)
to:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde border=0:)
February 23, 2010, at 08:14 PM by Tom Igoe -
Changed line 45 from:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/Midi/Midi.pde border=0:)
to:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/Midi.pde border=0:)
February 23, 2010, at 08:13 PM by Tom Igoe -
February 23, 2010, at 08:13 PM by Tom Igoe -
Changed line 45 from:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/MIDI.pde border=0:)
to:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/Midi/Midi.pde border=0:)
February 23, 2010, at 08:12 PM by Tom Igoe -
Changed lines 45-50 from:
%color=#7e7e7e%/*
%color=#7e7e7e% MIDI note player
%color=#7e7e7e%
%color=#7e7e7e% This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
%color=#7e7e7e% If this circuit is connected to a MIDI synth, it will play
%color=#7e7e7e% the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
to:
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/MIDI.pde border=0:)
Deleted lines 46-85:
%color=#7e7e7e%
%color=#7e7e7e% The circuit:
%color=#7e7e7e% * digital in 1 connected to MIDI jack pin 5
%color=#7e7e7e% * MIDI jack pin 2 connected to ground
%color=#7e7e7e% * MIDI jack pin 4 connected to +5V through 220-ohm resistor
%color=#7e7e7e% Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

%color=#7e7e7e% created 13 Jun 2006
%color=#7e7e7e% modified 2 Jul 2009
%color=#7e7e7e% by Tom Igoe
%color=#7e7e7e%
%color=#7e7e7e% http://www.arduino.cc/en/Tutorial/MIDI
%color=#7e7e7e%
%color=#7e7e7e% */

%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
%color=#7e7e7e%// Set MIDI baud rate:
%color=#cc6600%Serial%%.%color=#cc6600%begin%%(31250);
}

%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
%color=#7e7e7e%// play notes from F#-0 (0x1E) to F#-5 (0x5A):
%color=#cc6600%for%% (intnote = 0x1E; note < 0x5A; note ++) {
%color=#7e7e7e%//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
%color=#cc6600%delay%%(100);
%color=#7e7e7e%//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
%color=#cc6600%delay%%(100);
}
}

%color=#7e7e7e%// plays a MIDI note. Doesn't check to see that
%color=#7e7e7e%// cmd is greater than 127, or that data values are less than 127:
%color=#cc6600%void%% noteOn(%color=#cc6600%int%% cmd, %color=#cc6600%int%% pitch, %color=#cc6600%int%% velocity) {
%color=#cc6600%Serial%%.%color=#cc6600%print%%(cmd, %color=#006699%BYTE%%);
%color=#cc6600%Serial%%.%color=#cc6600%print%%(pitch, %color=#006699%BYTE%%);
%color=#cc6600%Serial%%.%color=#cc6600%print%%(velocity, %color=#006699%BYTE%%);
}
August 27, 2009, at 08:57 PM by Tom Igoe -
Changed lines 32-34 from:
to:
[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]

July 05, 2009, at 07:44 PM by Tom Igoe -
Changed lines 41-44 from:

[@
/*
MIDI note player
to:
(:div class=code :)

%color=#7e7e7e%/*
%color=#7e7e7e% MIDI note player
%color=#7e7e7e%
%color=#7e7e7e% This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
%color=#7e7e7e% If this circuit is connected to a MIDI synth, it will play
%color=#7e7e7e% the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
Changed lines 50-53 from:
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
to:
%color=#7e7e7e%
%color=#7e7e7e% The circuit:
%color=#7e7e7e% * digital in 1 connected to MIDI jack pin 5
%color=#7e7e7e% * MIDI jack pin 2 connected to ground
%color=#7e7e7e% * MIDI jack pin 4 connected to +5V through 220-ohm resistor
%color=#7e7e7e% Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
Changed lines 57-65 from:
The circuit:
* digital in 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

created 13 Jun 2006
modified 2 Jul 2009
by Tom Igoe
to:
%color=#7e7e7e% created 13 Jun 2006
%color=#7e7e7e% modified 2 Jul 2009
%color=#7e7e7e% by Tom Igoe
%color=#7e7e7e%
%color=#7e7e7e% http://www.arduino.cc/en/Tutorial/MIDI
%color=#7e7e7e%
%color=#7e7e7e% */
Changed lines 65-68 from:
http://www.arduino.cc/en/Tutorial/MIDI
to:
%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
%color=#7e7e7e%// Set MIDI baud rate:
%color=#cc6600%Serial%%.%color=#cc6600%begin%%(31250);
}
Changed lines 70-98 from:
*/

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (intnote = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.print(cmd, BYTE);
Serial.print(pitch, BYTE);
Serial.print(velocity, BYTE);
}


@]
to:
%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
%color=#7e7e7e%// play notes from F#-0 (0x1E) to F#-5 (0x5A):
%color=#cc6600%for%% (intnote = 0x1E; note < 0x5A; note ++) {
%color=#7e7e7e%//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
%color=#cc6600%delay%%(100);
%color=#7e7e7e%//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
%color=#cc6600%delay%%(100);
}
}

%color=#7e7e7e%// plays a MIDI note. Doesn't check to see that
%color=#7e7e7e%// cmd is greater than 127, or that data values are less than 127:
%color=#cc6600%void%% noteOn(%color=#cc6600%int%% cmd, %color=#cc6600%int%% pitch, %color=#cc6600%int%% velocity) {
%color=#cc6600%Serial%%.%color=#cc6600%print%%(cmd, %color=#006699%BYTE%%);
%color=#cc6600%Serial%%.%color=#cc6600%print%%(pitch, %color=#006699%BYTE%%);
%color=#cc6600%Serial%%.%color=#cc6600%print%%(velocity, %color=#006699%BYTE%%);
}

(:divend:)
July 03, 2009, at 12:51 AM by Tom Igoe -
Added lines 5-6:
This tutorial shows how to play MIDI notes from an Arduino.
Changed lines 17-18 from:
For more see this [[http://www.tigoe.net/pcomp/midi.shtml | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]]
to:
For more see this [[http://www.tigoe.net/pcomp/midi.shtml | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]].
Changed lines 27-29 from:
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

to:
July 03, 2009, at 12:50 AM by Tom Igoe -
Changed lines 5-16 from:
This tutorial on MIDI is still in progress. For more see http://itp.nyu.edu/physcomp/Labs/MIDIOutput
to:
[[http://en.wikipedia.org/wiki/MIDI|MIDI]], the Musical Instrument Digital Interface, is a useful protocol for controlling synthesizers, sequencers, and other musical devices. MIDI devices are generally grouped in to two broad classes: controllers (i.e. devices that generate MIDI signals based on human actions) and synthesizers (including samplers, sequencers, and so forth). The latter take MIDI data in and make sound, light, or some other effect.


MIDI is a serial protocol that operates at 31,250 bits per second. The Arduino's built-in serial port (all of them on the Mega as well) can send data at that rate.

MIDI bytes are divided into two types: '''command bytes''' and '''data bytes'''. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, and amount of pitch bend, and so forth. For more details, see the MIDI specification, or one of the many [[http://hinton-instruments.co.uk/reference/midi/protocol/index.htm|MIDI Protocol Guides]] on the Web.

MIDI data is usually notated in hexadecimal because MIDI banks and instruments are grouped in groups of 16.


For more see this [[http://www.tigoe.net/pcomp/midi.shtml | introduction to MIDI]] or this [[http://itp.nyu.edu/physcomp/Labs/MIDIOutput |example]]
Changed lines 18-19 from:
An LED connected to pin 9. use appropriate resistor as needed. For most common LEDs, you can usually do without the resistor, as the current output of the digital I/O pins is limited.
to:

All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:

* digital in 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor

Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

July 03, 2009, at 12:30 AM by Tom Igoe -
Changed lines 5-6 from:
MIDI
to:
This tutorial on MIDI is still in progress. For more see http://itp.nyu.edu/physcomp/Labs/MIDIOutput
Changed line 42 from:
http://www.arduino.cc/en/Tutorial/PIRSensor
to:
http://www.arduino.cc/en/Tutorial/MIDI
July 03, 2009, at 12:29 AM by Tom Igoe -
Changed lines 25-26 from:

to:
/*
MIDI note player

This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.


The circuit:
* digital in 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

created 13 Jun 2006
modified 2 Jul 2009
by Tom Igoe

http://www.arduino.cc/en/Tutorial/PIRSensor

*/

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (intnote = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.print(cmd, BYTE);
Serial.print(pitch, BYTE);
Serial.print(velocity, BYTE);
}

Deleted lines 73-74:

!!!Max code
July 03, 2009, at 12:15 AM by Tom Igoe -
Added lines 1-29:
''Examples > Communication''

!!MIDI Note Player

MIDI

!!!Circuit
An LED connected to pin 9. use appropriate resistor as needed. For most common LEDs, you can usually do without the resistor, as the current output of the digital I/O pins is limited.

click the image to enlarge

%width=400px%[[Attach:MIDI_bb.png | Attach:MIDI_bb.png]]


'''Schematic'''

click the image to enlarge

%width=400px%[[Attach:MIDI_schem.png | Attach:MIDI_schem.png]]


!!!Code

[@


@]

!!!Max code

Share