Pages: 1 [2]   Go Down
Author Topic: can't get basic midi sketch to work  (Read 2060 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Matt
« Last Edit: March 13, 2012, 12:27:38 am by mattsd » Logged

Lake Tyers Beach
Offline Offline
Full Member
***
Karma: 1
Posts: 100
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
 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.
 
 http://www.arduino.cc/en/Tutorial/MIDI
 
 */

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
  midi_com(my_channel,my_instrument);
  delay(200);  
}

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) {
  Serial.write(0x90+channel);
  Serial.write(pitch);
  Serial.write(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) {
  Serial.write(0x80+channel);
  Serial.write(pitch);
  Serial.write(velocity);
}
//  Sends a midi command. Does not check if
//  1<=channel<=16 or 1<=instrument<=128
void midi_com(int channel, int instrument) {
  Serial.write(0xC0+channel);
  Serial.write(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.

Rob

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.
« Last Edit: April 09, 2012, 02:50:01 am by robwlakes » Logged

Learning Flute and C++, heading for a meltdown.

Pages: 1 [2]   Go Up
Jump to: