Midi In for an Arduino

Thread Starter

Interitus

Joined Nov 8, 2009
34
I'm trying to an external MIDI device to control a set of LEDs through my arduino. I've been following the schematics here: http://m.bareille.free.fr/midithrubox/midithrubox.htm And have now tried the setup on this page: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1152354897/0
I have been able to send Midi messages to my arduino from the serial monitor in the arduino IDE, and it responds as expected. But I cant get any response at all from an external Midi device.
I'm using an Ardweeny, basically an ATmega328p with a programming backpack and status led, a 6N138 optocoupler, and a 74HC14 schmitt trigger. Currently I dont have the circuit hooked up through the schmitt trigger, just directly from the optocoupler. This is how I previously had the circuit hooked up: http://img829.imageshack.us/i/miditestrig1.jpg/ I'm also using jumper wires to just get power from the FTDI chip, so it wont interfere with the serial interface.

I've spent about two weeks or so trying to get this working, but I cant seem to get any results. I thought it was possibly the cheap drumpad I was using as a midi source, which only outputs on channel 10, but I've eliminated that by purchasing a new keyboard/synthesizer. Now I'm down to thinking that my optocouplers are bad? What else could it be? And if its the optocouplers, how do I test that?
 

Thread Starter

Interitus

Joined Nov 8, 2009
34
I'm using some slightly modified code from this page: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187962258/0 My modifications have just been to simplify it a bit for testing, here's the simplified bit:
Rich (BB code):
void loop () {
  if (Serial.available() > 0) {
    blink(); //once to signal at least something arrived

    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on
    if (incomingByte== 144){ // note on message starting starting
    // yeaha, we're getting something
    blink();
    blink();
    blink();
    }
 }

}
All the schematics I've seen for midi in to a microcontroller show the input coming straight from the optocoupler to the AVR, without going thru an inverter of any kind. Even in the original schematic I was following, it goes thru the inverter/schmitt trigger twice.
 
Ohhh i see i see.

Well i'd be careful... the hardware note for the code you posted seems to suggest that the optocoupler inverts the signal. You may want to look at the midi protocol spec and see whether or not your hardware needs to invert the signal.

Otherwise, i'd try and use the schmitt triggers. May not be the problem, but it will eliminate some chatter and maybe that's screwing up the transmission.

You would try testing the optocoupler setup with a push button and looking at the output and making sure it is correct
 
Well the breadboard pic is kinda hard to use for circuit debugging... a schematic might be a bit easier, but not necessary... i get the gist.

What do I look at the output with? and what am I looking for?
If you want to look at the optocoupler, probably the simplest thing to do would be something like described here: http://www.electronicrepairguide.com/optocoupler.html

You could probably hook up a battery and pushbutton too and measure the logic levels. Though i don't have much experience with optocouplers, so someone might chime in.

Also, it might be helpful to cout or printf (i forget what the arduino equivalent is) to the standard stream at a few points in your loop function to make sure you're getting into the if statements that you think you are.

Now that i think of it.... you might want to make sure this code is compatible with your version of the arduino (since its not the standard duemilanove). Just make sure the digital i/o match up?
 

bitrex

Joined Dec 13, 2009
79
MIDI uses negative logic, i.e. a positive 5 volts represents zero and 0 volts represents 1. The transistor in your optoisolator will invert that to the positive logic that your Arduino's UART expects, so there's no need to use an inverter between the optoisolator's output and the Arduino's UART input pin.

You should try testing your optoisolator to make sure it's working correctly. When you connect the input to the optoisolator's LED to ground, are you getting a HIGH logic level on the optoisolator's transitor collector? Similarly, when you connect the isolator's LED to a positive voltage through the 220 ohm resistor, are you getting a LOW votlage on the collector? Check and double check the connections from your MIDI DIN connector to your optoisolator circuit. The pin that goes to the 220 ohm resistor should show +5 volts when it's connected to a MIDI device and no signal is being sent.
 

Thread Starter

Interitus

Joined Nov 8, 2009
34
guitarguy12387: The code should be compatible, my board is just an ATMega328p, which is the same as many arduino boards.

Ok, I read the voltages off the DIN connector, and I'm getting 5V from pin 4 and 5 to the ground of the DIN connector. With the midi input connected to the LED of the optocoupler(DIN 4 and 5 connected), I get 5V from pin 6 to Gnd. With a 5V input through the led, I read 0.2V from pin 6 to ground. My digital meter is too slow to read changes if I hit keys on my midi keyboard.
 
Top