can't get basic midi sketch to work

hi,

i have a bit of a problem getting the the basic midi thing to work - Arduino uno r3.

i copy and pasted the code, the little tx led is blinking, i wired the midi.jack, i double checked all connections (by now, a few times more) ... yet nothing happens.
i'm using midiox for monitoring.

Does your MIDI-OX installation work with other MIDI devices such as a keyboard?

Have you tried hooking the Arduino to the input of a MIDI instrument to see if anything plays?

midiox is receiving data from other midi devices, on that midi-in.

no, other midi instruments don't receive data from the arduino as well.

Could the 220 ohm (Red Red Brown) resistor be faulty? Do you have a meter you could check it with?

i allready did ... seems fine to me ... replaced it (just in case)

The electrical specifications for the MIDI connector (Specs) shows a second 220 Ohm resistor from the TX pin to Pin 5 of the MIDI connector. Couldn't hurt to try that.

It might also help to connect the MIDI Ground pin (pin 2) to the shell of the MIDI connector.

still not working

For the output are you using Serial.write(value) or Serial.print(value, BYTE)? Are you using Arduino 0.23 or Arduino 1.0?

arduino 1.0

and i just copied the mentioned sketch.

This doesn't help solve, but I'm having the same problem with my R2. I'm a noob too, but I was able to reflash my UNO R2 with LUFA firmware and get it working via USB. This is no fun when you are trying to develop though, cause you have to constantly flash/reflash to get back to a state you can upload programs and do simple tests.

I've got the two 220ohm resistors, the connections appear to check out. I've done a loopback test and seen that my TX And RX pins appear to be working.

This is in Arduino 1.0, and before and after flashing to Arduino-usbserial-atmega16u2-Uno-Rev3.hex

Is something different about the UNO, or the UNO R2? I've triple checked my connections, even reversed them after reading it wouldn't hurt. I get nothing via MIDIOX, plugged into two different devices (Audiofire 4/Microkorg) and just can't get anything. I use the same cable and same midi in and get activity from other devices.

I've tried the midi library and just straight up serial at 31250.

Checked the midi cables, they are fine. I've tried two known working MIDI cables, a longer one, and one that is just 1ft long. I've also tried using only a wall wart power supply. What gives?

Matt

Wanted to add further to this discussion. I'm on a brand new Arduino Uno R3. Mac OS 10.5 for development. I'm new to working with the Arduino and new to Midi as well (at least from a hardware standpoint).

I also am unable to get the basic midi sketch to function. I've constructed the midi output exactly to spec with the midi.org electrical specifications (even going as far as including the buffer). At one point my midi device, a Motu 828mk3 Interface was receiving midi messages in sync with when I sent them, however the message information was nonsensical. I have been unable to repeat this result with the same setup and code.

Neither Software Serial nor onboard Serial output seems to work. I've tested with the Arduino Uno still connected via USB to the computer and disconnected with an external power source.

I'm getting a 6N138 in within a day or so to try and receive midi input to spec. Hopefully that may shed some more light if this is purely a serial output problem of if it's having trouble receiving at this rate as well.

Other things I've tested:

I've tested sending a byte from Software Serial at 13250 into the Arduino's built in serial port and this works fine (10 consecutive bytes received correctly, then output over hardware serial port to a computer). This worked correctly at 9600, 13250, and 14400.

I hooked things up to an oscilloscope today and the timing looks well within tolerance (every bit taking approx 32 microseconds) so this doesn't seem to be a timing issue. Everything is completely as expected, start bit etc.

I'm certain the midi input I'm using works and the software (Logic Pro) can monitor valid midi input.

Will post further updates as I try some more things.

Interesting. I forgot also to mention that I also had no luck with the SoftSerial or NewSoftSerial libraries. I saw you mentioned 13250 twice, you mean 31250 right?

I don't have an oscilloscope, so I think I've exhausted most of the things I can do from a multimeter and software troubleshooting angle. Really disappointing cause this is my first hardware project and I had to go the USB Flash software route to make it work. :slight_smile:

Same sketch works with MOCO for Lufa, so I think that rules out the code or the MIDI library.

^Yes, 31250, not 13250. I don't think the onboard Serial connection will work very well at 13250, haha.

Strange and frustrating indeed.

Like John said on reply 5, use a real midi circuit.

I use the 6N136 (I had some spare) and this is the non-Darlington Pair version of the 6N138.
If you choose to also use a 6N136, then use a 4.7k resistor instead of the 280 ohm spec'd in the midi standard.

I dont always use the two not gates (7404) but you should since it really cleans up the edges.

The common issues with Arduino and midi appear to be

  • Not using an approved midi circuit - you do want to protect your Arduino/other Midi gear right?
  • Using Serial (ie pins 1/2) whilst the program is uploading/Midi is sending
  • When receiving, not checking for available bytes (Serial.available()) -- the -1 will be interpreted as 255
    and this is a valid midi status ... one you really dont want to deal with
  • Not considering running status, if your gear sends running status
  • wiring the 5 pin din round the wrong way

You can find my hardware sketch half way down my http://miniaktools.sourceforge.net/ page.
I havent used the 7404 in this one (they were still on order :-().

I have various issues with UART buffer lag when handling large sysex, but the hardware/software I wrote works well enough.

Good luck with your midi project.

Regards

Steve H

Thought I would update the thread since I'd replied earlier.

Currently I'm successfully both receiving and transmitting midi messages (Software Serial and hardware Serial).

I got some new parts in this week, and that seems to be doing to the trick. I built the circuit to the specs on the midi electrical specification schematic. For the output I used an inverter and an NPN transistor as the buffer, 1K resistor into the base. One thing that continued to throw me was that the midi spec shows pin values as they appear on a midi cable (male), not as they are on a 5-Pin DIN jack (female). This makes a rather large difference.

For the midi input I used a 6N138 optocoupler. The input side of the 6N138 was exactly as specified on the midi spec. On the output side, I used a 220 ohm resistor into the V0 pin and a 1K resistor into the Vcc pin (both resistors getting 5V from the Arduino's power supply). The data receive line from the Arduino was connected at the same point as the 220 ohm resistor and the V0 pin's connection.

Everything seems to be working great now. Hope any of this might help.

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

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.

/*
 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.