Hide minor edits - Show changes to markup
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/04.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/4.Communication/MIDI/Midi.ino lang=arduino tabwidth=4:)
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.
(: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:)
statements: any valid statements
Examples > Communication
This tutorial shows how to play MIDI notes from an Arduino.
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 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 introduction to MIDI or this example.
Hardware Required
All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:
click the image to enlarge
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic
click the image to enlarge
(: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()
for() loop
Examples > Communication
This tutorial shows how to play MIDI notes from an Arduino.
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 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 introduction to MIDI or this example.
Hardware Required
All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:
click the image to enlarge
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic
click the image to enlarge
(: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()
for() loop
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.
(: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:)
statements: any valid statements
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
(:source https://raw.github.com/arduino/Arduino/master/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4 border=0:)
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde border=0:)
(:source http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde lang=arduino tabwidth=4 border=0:)
See Also:
serial.begin()
for() loop
(:divend:)
(:divend:)
See Also:
serial.begin()
serial.read()
switch() case
if() statement
digitalWrite()
See Also:
serial.begin()
for() loop
Hardware Required
For more see this introduction to MIDI or this example.
For more see this introduction to MIDI or this example.
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/Midi.pde border=0:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/4.Communication/MIDI/Midi.pde border=0:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/Midi/Midi.pde border=0:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/Midi.pde border=0:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/MIDI.pde border=0:)
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/Midi/Midi.pde border=0:)
/* 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.
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/MIDI/MIDI.pde border=0:)
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/MIDI */
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); }
image developed using Fritzing. For more circuit examples, see the Fritzing project page
[@ /*
MIDI note player
(:div class=code :)
/* 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.
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.
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
created 13 Jun 2006 modified 2 Jul 2009 by Tom Igoe http://www.arduino.cc/en/Tutorial/MIDI */
http://www.arduino.cc/en/Tutorial/MIDI
void setup() { // Set MIDI baud rate: Serial.begin(31250); }
*/
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);
}
@]
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); }
(:divend:)
This tutorial shows how to play MIDI notes from an Arduino.
For more see this introduction to MIDI or this example
For more see this introduction to MIDI or this example.
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
This tutorial on MIDI is still in progress. For more see http://itp.nyu.edu/physcomp/Labs/MIDIOutput
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 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 introduction to MIDI or this example
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.
All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the Arduino:
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
MIDI
This tutorial on MIDI is still in progress. For more see http://itp.nyu.edu/physcomp/Labs/MIDIOutput
http://www.arduino.cc/en/Tutorial/PIRSensor
http://www.arduino.cc/en/Tutorial/MIDI
/*
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);
}
Examples > Communication
MIDI
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
Schematic
click the image to enlarge