Midi In for an Arduino

Discussion in 'Embedded Systems and Microcontrollers' started by Interitus, Oct 17, 2010.

  1. Interitus

    Thread Starter Member

    Nov 8, 2009
    34
    0
    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?
     
  2. guitarguy12387

    Active Member

    Apr 10, 2008
    359
    12
    What code are you using?

    Also, the 74HC14 is the inverter, too... how are you doing the inversion if you're not using the schmitt trigger?
     
  3. Interitus

    Thread Starter Member

    Nov 8, 2009
    34
    0
    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:
    Code ( (Unknown Language)):
    1. void loop () {
    2.   if (Serial.available() > 0) {
    3.     blink(); //once to signal at least something arrived
    4.  
    5.     // read the incoming byte:
    6.     incomingByte = Serial.read();
    7.  
    8.     // wait for as status-byte, channel 1, note on
    9.     if (incomingByte== 144){ // note on message starting starting
    10.     // yeaha, we're getting something
    11.     blink();
    12.     blink();
    13.     blink();
    14.     }
    15.  }
    16.  
    17. }
    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.
     
  4. guitarguy12387

    Active Member

    Apr 10, 2008
    359
    12
    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
     
  5. Interitus

    Thread Starter Member

    Nov 8, 2009
    34
    0
    Looking at the datasheet for my optocoupler, I am inverting the signal. I've hooked it up to the schmitt trigger and I'm still not getting anything. Here is a picture of my breadboard: http://img26.imageshack.us/i/midibreadboard2.jpg/

    What do I look at the output with? and what am I looking for?
     
  6. guitarguy12387

    Active Member

    Apr 10, 2008
    359
    12
    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.

    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?
     
  7. bitrex

    Member

    Dec 13, 2009
    79
    4
    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.
     
  8. Interitus

    Thread Starter Member

    Nov 8, 2009
    34
    0
    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.
     
Loading...