[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”MIDI Introduction” tab_id=”1393229943-1-44″][vc_column_text]MIDI (short for Musical Instrument Digital Interface) is a technical standard that describes a protocol, digital interface and connectors and allows a wide variety of electronic musical instruments, computers and other related devices to connect and communicate with one another. A single MIDI link can carry up to sixteen channels of information, each of which can be routed to a separate device.
MIDI carries event messages that specify notation, pitch and velocity, control signals for parameters such as volume, vibrato, audio panning, cues, and clock signals that set and synchronize tempo between multiple devices. These messages are sent to other devices where they control sound generation and other features. This data can also be recorded into a hardware or software device called a sequencer, which can be used to edit the data and to play it back at a later time.
MIDI technology was standardized in 1983 by a panel of music industry representatives, and is maintained by the MIDI Manufacturers Association (MMA). All official MIDI standards are jointly developed and published by the MMA in Los Angeles, California, US, and for Japan, the MIDI Committee of the Association of Musical Electronics Industry (AMEI) in Tokyo.
We will use a USB to MIDI cable shown below to act as control device.
The software we used is HappyEO, HappyEO is a software simulates electronic instrument. We can play wonderful music with the software.
Picture 3 HappyEO electronic organ
[/vc_column_text][/vc_tab][vc_tab title=”Parts List” tab_id=”1393229943-2-45″][vc_column_text]
- Application software: HappyEO
- 1 x Arduino Uno
- 1 x MIDI Shield
Note: we treat Arduino+MIDI Shield as a sound source. Arduino send sthe data and command with 31.25x( 1±0.01)KBaud through the USB to MIDI cable. PC outputs the music with the data and command.[/vc_column_text][/vc_tab][vc_tab title=”Steps” tab_id=”1393230560608-2-1″][vc_column_text]We will follow steps shown below:
- Load the sample code to Arduino.
- Install MIDI shield onto Arduino Uno.
- Connect one end of MIDI to USB cable to MIDI shield, and the other end of MIDI to USB cable to the PC.
- Once we insert the USB cable to PC, PC will recognize the cable.
- Launch software HappyEO, and click “Options”, enable MIDI input device, and select USB Audio Device.
If you select the USB AUDIO DEVICE as the input device, and select software synthesizers as the output device, you can hear the music sent from Arduino with an earphone connected to PC, and you can see LEDs of Arduino are blinking.
If you select the USB AUDIO DEVICE as the output device, HappyEO can send the data and command to Arduino when we press the keyboard,the led will blink when it received data.
Wiring:
- MIDI OUT of USB to MIDI cable -> MIDI IN of MIDI Shield
- MIDI IN of USB to MIDI cable -> MIDI OUT of MIDI shield
[/vc_column_text][/vc_tab][vc_tab title=”Test code ” tab_id=”1393231068929-3-3″][vc_column_text]The code can be downloaded from github.
We reproduce here the code we used in previous section for convince:
// defines for MIDI Shield components only #define KNOB1 0 #define KNOB2 1 #define BUTTON1 2 #define BUTTON2 3 #define BUTTON3 4 #define STAT1 7 #define STAT2 6 #define OFF 1 #define ON 2 #define WAIT 3 byte incomingByte; byte note; byte velocity; int pot; byte byte1; byte byte2; byte byte3; int action=2; //1 =note off ; 2=note on ; 3= wait void setup() { pinMode(STAT1,OUTPUT); pinMode(STAT2,OUTPUT); pinMode(BUTTON1,INPUT); pinMode(BUTTON2,INPUT); pinMode(BUTTON3,INPUT); digitalWrite(BUTTON1,HIGH); digitalWrite(BUTTON2,HIGH); digitalWrite(BUTTON3,HIGH); for(int i = 0;i < 10;i++) // flash MIDI Sheild LED's on startup { digitalWrite(STAT1,HIGH); digitalWrite(STAT2,LOW); delay(30); digitalWrite(STAT1,LOW); digitalWrite(STAT2,HIGH); delay(30); } digitalWrite(STAT1,HIGH); digitalWrite(STAT2,HIGH); //start serial with midi baudrate 31250 Serial.begin(31250); } void loop () { //*************** MIDI OUT ***************// pot = analogRead(0); note = pot/8; // convert value to value 0-127 if(button(BUTTON1) || button(BUTTON2) || button(BUTTON3)) { Midi_Send(0x90,note,0x45); while(button(BUTTON1) || button(BUTTON2) || button(BUTTON3)); } //*************** MIDI LOOPBACK ******************// if(Serial.available() > 0) { byte1 = Serial.read(); byte2 = Serial.read(); byte3 = Serial.read(); Midi_Send(byte1, byte2, byte3); } //*************** MIDI IN ***************// if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); // wait for as status-byte, channel 1, note on or off if (incomingByte== 144) // Note on { action = OFF; } else if (incomingByte== 128) // Note off { action = ON; } else if (note==0 && action != WAIT) // note on, wait for note value { note=incomingByte; } else if (note!=0 && action != WAIT) // velocity { velocity=incomingByte; if(action == ON){ Midi_Send(0x90,note,velocity); } if(action == OFF){ Midi_Send(0x80,note,velocity); } note=0; velocity=0; action=WAIT; } else{ } } } void Midi_Send(byte cmd, byte data1, byte data2) { Serial.print(cmd, BYTE); Serial.print(data1, BYTE); Serial.print(data2, BYTE); } void blink(){ digitalWrite(STAT1, HIGH); delay(100); digitalWrite(STAT1, LOW); delay(100); } char button(char button_num) { return (!(digitalRead(button_num))); }
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.