Go Down

Topic: can't get basic midi sketch to work (Read 6330 times) previous topic - next topic


Mar 13, 2012, 06:24 am Last Edit: Mar 13, 2012, 06:27 am by mattsd Reason: 1
Just wanted to reply and say that I punted and just got a midi shield for 17 bucks.  http://ruggedcircuits.com/html/flexible_midi_shield.html

This thing works great, so far so good, even with SoftSerial.  Since I was more interested in controlling my music equipment in an interesting way than dealing with octocouplers, I just went that route.  When I get some free time maybe I'll suck it up and take my skills to the next level.  

Thanks for your help and advice everyone, not sure why this is the first time I've seen people mentioning how to build a real midi circuit when everyone seems to get by with that 220hm resistor in their projects that they post online.  Wondering how they got by without the real circuit and if they know what risks they are taking.



Mar 31, 2012, 01:05 am Last Edit: Apr 09, 2012, 09:50 am by robwlakes Reason: 1
I had similar problems getting the Midi sketch as supplied in 1.0 to work, and having had some experience with Picaxes and Midi knew the hardware was OK.  In the end I transferred the essentials from my own Picaxe code, modified the Arduino example with a more formal midi structure, and found it worked without any further hardware modifications.  I have tested it on a ROLAND MT-32, an old machine, but a classic and a standard.

Code: [Select]
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 repeat
the chromatic scale from F#-0 (0x1E) to F#-5 (0x5A).

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

created 13 Jun 2006
modified 30 Aug 2011
by Tom Igoe
Modified by Rob Ward
23 March 2012
Tested on a Roland MT-32 (a classic!)

This example code is in the public domain.



const int my_channel=1;  // on Channel 1 :-)
const int my_instrument=1;  // Acoustic Piano
     int my_velocity=96;  //max=127, min=0 volume
void setup() {
 //  Set MIDI baud rate:
 Serial.begin(31250); //standard midi serial baud rate
 delay (200);
 //Establish channel and Instrument

void loop() {
 // play notes from F#-0 (0x1E) to F#-5 (0x5A):
 for (int pitch = 0x1E; pitch < 0x5A; pitch ++) {
   midi_note_on(my_channel, pitch, my_velocity);
   delay(100);// sets duration of the note
   //Turn off the note begun above
   midi_note_off(my_channel, pitch, 0);  
   delay(100);// sets separation between notes

//  Starts a MIDI note.  Doesn't check to see that
//  1<=channel<=16, or that data values are less than 127
void midi_note_on(int channel, int pitch, int velocity) {
//  Stops a MIDI note.  Doesn't check to see that
//  1<=channel<=16, or that data values are less than 127
void midi_note_off(int channel, int pitch, int velocity) {
//  Sends a midi command. Does not check if
//  1<=channel<=16 or 1<=instrument<=128
void midi_com(int channel, int instrument) {

Obviously it does not address any midi input into the Arduino, but the chances of this sketch at least getting you to first base in sending midi from your Arduino are greatly improved.
The original Arduino sketch was too simplified for me, and apparently the same for my old Roland.


PS I used two 200ohm resistors, one from the 5V to the midi socket, and the other 200ohm from the output pin to the midi socket.  If either accidentally get shorted to ground or 5V then no damage will be done.
Learning Flute and C++, heading for a meltdown.

Go Up