Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 13 of 13

Thread: 5 pin MIDI in not working

  1. #1

    5 pin MIDI in not working

    Hi! I'm using a teensy 4.0 on a breadboard and trying to get 5 PIN MIDI in to work. I'm using the code and following the schematic from PJRC's Teensyduino library / MIDI located here

    Here is the schematic (I'm only using the MIDI in side, not the MIDI out):

    Click image for larger version. 

Name:	schematic.png 
Views:	24 
Size:	4.9 KB 
ID:	28339

    Here is the code:

    Code:
    /* MIDI Input Test - for use with Teensy or boards where Serial is separate from MIDI
     * As MIDI messages arrive, they are printed to the Arduino Serial Monitor.
     *
     * Where MIDI is on "Serial", eg Arduino Duemilanove or Arduino Uno, this does not work!
     *
     * This example code is released into the public domain.
     */
     
    #include <MIDI.h>
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
      MIDI.begin(MIDI_CHANNEL_OMNI);
      Serial.begin(57600);
      Serial.println("MIDI Input Test");
    }
    
    unsigned long t=0;
    
    void loop() {
      int type, note, velocity, channel, d1, d2;
      if (MIDI.read()) {                    // Is there a MIDI message incoming ?
        byte type = MIDI.getType();
        switch (type) {
          case midi::NoteOn:
    
            note = MIDI.getData1();
            velocity = MIDI.getData2();
            channel = MIDI.getChannel();
            if (velocity > 0) {
              Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
            } else {
              Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
            }
            break;
          case midi::NoteOff:
            note = MIDI.getData1();
            velocity = MIDI.getData2();
            channel = MIDI.getChannel();
            Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
            break;
          default:
            d1 = MIDI.getData1();
            d2 = MIDI.getData2();
            Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
        }
        t = millis();
      }
      if (millis() - t > 10000) {
        t += 10000;
        Serial.println("(inactivity)");
      }
    }
    Here is my actual circuit:

    Click image for larger version. 

Name:	midi in 2.jpg 
Views:	11 
Size:	76.9 KB 
ID:	28340
    Click image for larger version. 

Name:	MIDI in 1.jpg 
Views:	7 
Size:	77.8 KB 
ID:	28341

    The code uploads fine and shows "MIDI Input test" on the serial moniter and then (inactivity) every 10 seconds and nothing else.

    I have tested each wire with a multimeter and they all work. The Teensy works and I've gotten it to send 5 pin midi out previously. I tested the two resistors and they are the correct Ohms. I tested the diode and it's good.

    The chip is a 6N138 and it came in a pack of 10. I have swapped out 3 of them and get the same result. They seem to be good though because when I took the wire going to Teensy pin 0 (Rx) and attached it to Pin 7 of the 6N138 and then ungrounded and regrounded the 6N138 (I did this by accident), the Teensy program read:

    Message, type= 255, data = 0 0

    Actually, I don't know if that means the chip is working or not. I note that this was an accident and the wire in question should go from Rx (pin 0 of the teensy) to pin 6 of the 6N138. I had attached it accidentally to 7 instead, which is when I got this weird result. This is the only time that the serial monitor has shown any MIDI activity.

    I read on the PJRC MIDI library I linked to above that some 6N138s need pin 7 grounded through a 10k resistor and I tried that too. Also nothing.


    I am using a keyboard (garageband keytar) attached by 5 pin midi that I tested elsewhere and worked (I also tried with an alternative keyboard, a Keystep, as well just in case, same result)
    An additional piece of information is that the keyboard is designed to blink when it is on but not plugged into MIDI and then stop blinking when it is connected to MIDI. In this case, when I plug the keyboard MIDI into my circuit, the keyboard stops blinking, meaning the keyboard "thinks" it is attached to MIDI. Again though, NOTHING comes through on the serial monitor side except (inactivity) with the exception of the weird fluke I described above.

    I have been staring at this thing / thinking about this for hours. I've checked and rechecked the connection of every component and I just cannot figure out what I'm missing. Any ideas would be GREAT. I'm at the point of thinking of abandoning 5 pin MIDI in and instead going for a Teensy 4.1 with USB host, which I've gotten working before. However, I would strongly prefer 5 pin midi in and host USB for this project.

    Thank you so much in advance!

  2. #2
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    232
    Hi @Tombot7 - the Teensy 4 pins are not 5v tolerant, it looks like you are driving them to 5v which will likely cause damage. They are designed for 3.3v.

    Either use a Teensy 3.x which can take 5v or look at a different circuit.

    Cheers Paul

  3. #3
    Hi Paul. Thanks for the reply. I checked out the link you sent and it is the same circuit, with the only change that it adds a 4.7k resistor going to ground on pin 7. It also suggests powering the optoisolater with 3.3 volts instead of 5 volts. I tried both and neither worked.

    I also tried hooking up the circuit to my 5 volt arudino, but when I tried to upload the code, it wouldn't recognize MIDI.h anymore.

    Ugh.

  4. #4
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    232
    Hi - in that link it is the second circuit - with a different opt-isolator

    https://diyelectromusic.files.wordpr...1023&h=&zoom=2

  5. #5
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    756
    When you had it hooked up to 5v you may have destroyed the pins.
    Check by trying to use them as Serial1 pins to another MCU (or I suppose you could connect Rx to Tx ) to see if they still function ok.
    No good saying "oh the circuit/software does not work" if the pins don't any more.

  6. #6
    Hi! I ordered the other optoisolater. Sounds like that has more chance of working with 3.3 volt. Thank you!

  7. #7
    Quote Originally Posted by BriComp View Post
    When you had it hooked up to 5v you may have destroyed the pins.
    I don't think so. I just tested it by connecting 1 to 0 and writing a simple program. Seems fine.

    The circuit I was using said it was safe for 3.3volt. Although the optoisolator is powered by 5 volt and it's input is 5 volt, the output side should only output at max what it's pulled up to, is my understanding. I never pulled it past 3.3 volts, so I think I'm okay.

    But thanks for the response though.

  8. #8
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    756
    Ok, that's good. Hope new opto-isolator solves your problem.

  9. #9
    Member
    Join Date
    Jun 2019
    Location
    Sydney, Australia
    Posts
    42
    Your circuit is fine and won't damage the Teensy.

    it's very easy to get pins 4 & 5 mixed up on the DIN - that's what I'd check closely. Specifically - make sure you are viewing the connector from the intended direction.

    You might consider adding a resistor and LED off pin 6 (connected to VCC) so you can watch the MIDI activity directly.

  10. #10
    Quote Originally Posted by kallikak View Post

    You might consider adding a resistor and LED off pin 6 (connected to VCC) so you can watch the MIDI activity directly.
    Thatís a great idea. Thank you very much.

    What resister value should I use?

    (I donít really understand how ďpulling upĒ to 3.3 volts works from this optoisolater. What is the value of the signal the device is outputting? And how is connecting 3.3 volts through a resister changing that value to 3.3 volts?)

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,392
    Quote Originally Posted by Tombot7 View Post
    What resister value should I use?

    (I don’t really understand how “pulling up” to 3.3 volts works from this optoisolater. What is the value of the signal the device is outputting? And how is connecting 3.3 volts through a resister changing that value to 3.3 volts?)
    Connect another resistor to pin 6 on the 6N138 optocoupler. Then connect a LED between the other leg of that resistor and 3.3V, where the cathode (flat edge of the LED) connects to the resistor and the anode connects to 3.3V.

    Best to use a red LED and 330 or 470 ohm resistor. Blue or very bright green LEDs may not be reliable, as they often need close to 3 volts. Red LEDs usually need less than 2 volts (where the other ~1.3 volts will be across the resistor).

    The idea is when MIDI signal is incoming, it turns on the optocoupler. When pin 6 is low, the LED will light up.

  12. #12
    I havenít had a chance to try this yet. I was hoping to before responding but it might take me a few days. I did want to say thanks in the meantime and how much I enjoy Teensy as well as appreciate this forum.

  13. #13
    Quote Originally Posted by BriComp View Post
    Ok, that's good. Hope new opto-isolator solves your problem.
    H11L1 for the win. Worked perfectly with the teensy 5 pin midi example program. The circuit is just 4 cables, 2 resisters and a diode. If anybody is reading this trying to decide on an optoisolator -- This is one vote for the H11L1 for 3.3 volt microcontroller over the 6N138.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •