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

Thread: MIDI In problem with Teensy 2

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    11

    MIDI In problem with Teensy 2

    Hi
    I am using a Teensy 2 and want to to get MIDI In from a 5 pin DIN.
    I am using a 6N138 based circuit, instead of a PC900 like recommended here: https://www.pjrc.com/teensy/td_libs_MIDI.html
    I am getting unexpected values on my MIDI in port, they seem shuffled.
    Could the 6N138 be the reason for the unpredictable results?

    (I know I am supposed to follow the recommendations, but I was previously using a 6N138 with a Teensy LC, which was working fine, and I am having troubles finding a PC900 for SMT, so I wanted to give the 6N138 a try).

  2. #2
    Senior Member
    Join Date
    Apr 2019
    Posts
    111
    Hello, how are you sending MIDI to the Teensy? 6N138 based circuits work fine, do you have the circuit diagram that you used?

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    11
    Well, the diagram is a bit of a mess right now, I'll try to clear it up and post it if needed. But the 6N138 part is similar to the one on the pjrc website.

    Just to give you an idea of what happens, here's a screenshot of MIDI Monitor.
    Basically, I have a note 60, velocity 100 channel1 sent every second to "Port 1" (note off 1 sec later, vel 64). Port 1 is harwdware MIDI Out port from my soundcard, which is connected to the Teensy 2 MIDI In port (the one with the 6N138).
    The Teensy (renamed SotL Mk2) is supposed to send the received note back to its usbMIDI port, as per the code below.
    So we are supposed to see "To Port 1 note 60 vel 100 channel 1" and just below, "Form SotL Mk2 note 60 vel 100 channel1", but as you can see, the result is unpredictable (although not completely random, I can see a pattern...)

    So the 6N138 does receive data. It's just that the MIDI data seems a bit shuffled from time to time.

    Click image for larger version. 

Name:	Capture díécran 2020-09-26 à 19.51.57.jpg 
Views:	8 
Size:	97.6 KB 
ID:	21870


    Code:
    #include <MIDI.h>
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
      MIDI.begin(MIDI_CHANNEL_OMNI);
      MIDI.turnThruOff();
      MIDI.setHandleControlChange(onControlChange); 
      MIDI.setHandleNoteOn(onNoteOn); 
      MIDI.setHandleNoteOff(onNoteOff);
    }
    
    void loop() {
      MIDI.read();
      }
    
    void onControlChange(byte channel, byte control, byte value) { 
      usbMIDI.sendControlChange(control, value, channel);    
     }
    
    void onNoteOn(byte channel, byte note, byte velocity) { 
      usbMIDI.sendNoteOn(note, velocity, channel);
    }
        
    void onNoteOff(byte channel, byte note, byte velocity) { 
      usbMIDI.sendNoteOff(note, velocity, channel);
    }

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,488
    Teensy LC is a 3V3 device, Teensy 2 is a 5V device. Would the MIDI circuit need to be modified to handle the difference and did you do that?

    Pete

  5. #5
    Junior Member
    Join Date
    May 2018
    Posts
    11
    Quote Originally Posted by el_supremo View Post
    Teensy LC is a 3V3 device, Teensy 2 is a 5V device. Would the MIDI circuit need to be modified to handle the difference and did you do that?

    Pete
    Well, I think it would only be relevant for the out port (Tx), the In port shouldnít be affected as far as I know.

    But in any case, I have no clue why the Teensy 2 is supposed to be used with a PC900. I would be interested to know the reason.

  6. #6
    Junior Member
    Join Date
    May 2018
    Posts
    11
    APOLOGIES!!! I didnít mean a 6N138, but a 4N35.
    The 4N35 was working fine with the LC, but is acting with the T2.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,034
    Wow, pretty lucky to get 4N35 to work with any board. It's a slow optocoupler, just marginal for MIDI.

  8. #8
    Junior Member
    Join Date
    May 2018
    Posts
    11
    Thanks Paul for the feedback.
    Well, I managed to get it working fine with the LC.

    Ok, going to move to 6N138 as I’m having a hard time finding PC900 in SMT.

    While you’re (hopefully) reading this message, just want to thank you for your products and dedication.
    Cheers

  9. #9
    Junior Member
    Join Date
    May 2018
    Posts
    11
    FYI, replacing the 4N35 by a 6N138 fixed it.

Posting Permissions

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