How to make a MIDI output using a microcontroller

Post Reply
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

How to make a MIDI output using a microcontroller

Post by Shane » Fri Jun 24, 2011 7:00 am

This tutorial explores the basics of MIDI (Musical Instrument Digital Interface) communication. MIDI was developed in early 1980's to be an industry standard protocol to be used for musical instruments, computers and other devices to communicate. MIDI's use has continued to expand and is now used not only as the standard protocol for musical instruments, but for applications such as cell phone ring tones and lighting control systems.

A standard MIDI message (following General MIDI or GM Standard) will contain a Status Byte followed by either one or two Data Bytes (Status, Data 1, Data 2). Following are some of the most common MIDI messages and are the ones used in this example:
note on number channel 1(0x90), note number (0-127), velocity (0-127)
note off number channel 1(0x80), note number (0-127), velocity (0-127)
program change number channel 1(0xC0), instrument number (0-127)

In this example, we connect the MIDI standard 5-Pin DIN connector from our Arduino circuit (MIDI OUT) to the MIDI IN of a standard sound module (we use an Alesis Nanosynth, but any standard MIDI sound module will work.)
1.jpg
1.jpg (39.17 KiB) Viewed 5321 times

Code: Select all

//MIDI OUTPUT (SERIAL)

//GENERATE MIDI DATA USING RANDOM TO DEMONSTRATE
 //SENDING MIDI DATA USING THE ARDUINO SERIAL OUT
 //AND THE USE OF THE RANDOM FUNCTION

//DECLARE VARIABLES

int note = 0;

void setup() {
 //SET BAUD RATE FOR MIDI 
 Serial.begin(31250);
 }

void loop (){
 //USE RANDOM FUNCTION TO SELECT NOTES BETWEEN C1 AND C7
 //NOTE C = MIDI NOTE NUMBER 12
 //NOTE C7 = MIDI NOTE NUMBER 96
 note = random(12,96);
 // SEND THE MIDI COMMAND TO PLAY A NOTE ON CHANNEL 1 (0X90), PLAY NOTE VALUE (note), HIGH VELOCITY
 sendMidiNote (0x90, note, 0x7F);
 delay (50); //LEAVE NOTE ON FOR 50 MILLISECS
 //SEND THE MIDI NOTE OFF COMMAND, NOTE PREVIOUSLY PLAYED, HIGH VELOCITY
 sendMidiNote (0x80, note, 0x7F);
 delay (50); //REST FOR 50 MILLISECS

}

//THIS FUNCTION PLAYS A MIDI NOTE WHEN midiCommand = 0x90
 //THIS FUNCTION TURNS OFF THE NOTE WHEN midiCommand = 0x80

void sendMidiNote (byte midiCommand, byte noteValue, byte velocityValue){
 Serial.print(midiCommand, BYTE);
 Serial.print(noteValue, BYTE);
 Serial.print(velocityValue, BYTE);
 }
2.jpg
2.jpg (101.4 KiB) Viewed 5321 times
3.jpg
3.jpg (204.6 KiB) Viewed 5321 times
4.jpg
4.jpg (165.17 KiB) Viewed 5321 times
Courtecy of UMASS AMHERST
DeepakPatil23
Sergeant
Sergeant
Posts: 20
Joined: Mon May 23, 2011 7:16 pm

Re: How to make a MIDI output using a microcontroller

Post by DeepakPatil23 » Mon Jul 11, 2011 2:55 pm

Images are not seen .
Is it possible with out ARDUINO. using only pic??
:?:
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to make a MIDI output using a microcontroller

Post by Neo » Mon Jul 11, 2011 4:40 pm

Images will be recovered within the next few days.

Refer to ROBOT.LK moved to a new server post to get latest information on that.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to make a MIDI output using a microcontroller

Post by Neo » Thu Jul 14, 2011 12:34 pm

Hi Deepak,

We have fixed the images and attachments on the forum now. Can you check please?
If you find any problem, please let me know.
Post Reply

Return to “Arduino”