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

Thread: Can Teensy 3.x receive MIDI on pin 7 or 9? Or is it really only Serial1?

  1. #1
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37

    Can Teensy 3.x receive MIDI on pin 7 or 9? Or is it really only Serial1?

    MIDI.h says...
    Code:
    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT         Serial1
    #endif
    ...but the date on that file is older than Teensy 3 (which introduced 3 serial ports). Am I supposed to be able to "#define USE_SERIAL_PORT Serial3" now? Or can this be handled in the sketch?

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,811
    Try changing it in MIDI.h - it should work.

    Pete

  3. #3
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    That's good to know. It means 3 things.

    1) Maybe MIDI.h needs an update.
    2) I don't need to re-solder anything.
    3) My problem with getting MIDI input is something else.

    For starters I've edited MIDI.h to use serial port 3 and I'm trying this...
    Code:
    #include <MIDI.h>
    
    void setup() {
      MIDI.begin(MIDI_CHANNEL_OMNI);
    }
    
    void loop() {
      if (MIDI.read()) {
        Serial.println("there's MIDI");
      }
    }
    Getting nothing.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,811
    What MIDI device do you have connected to Serial3?
    If it can receive note on/off, add some code to the setup function to send a note to it.


    Pete

  5. #5
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    I've got an Alesis Performance Pad plugged into a MIDI IN connector which is routed to pin 7 on my Teensy 3.1 according to (the left side of) this schematic.
    Click image for larger version. 

Name:	td_libs_MIDI_sch.gif 
Views:	139 
Size:	5.1 KB 
ID:	5883
    The quality of my craftsmanship is certainly in question but I want to make sure I'm testing with code that should definitely be working before I go pulling things apart again. Having the drum pad plugged in an beating on it should be enough to get MIDI.read() to register TRUE shouldn't it?
    Last edited by monkeybiscuits; 12-22-2015 at 03:42 PM. Reason: new image includes the proper MIDI out circuit

  6. #6
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    959
    I have had midi send on all. There is code and some discussion here: https://forum.pjrc.com/threads/31315...highlight=midi
    The thread refers to using littlescales work on sending beat, but usefully reminds to add serial1 2 and 3 .begin to setup...
    void setup() {
    Serial.begin(31250);
    Serial1.begin(31250);
    Serial2.begin(31250);
    Serial3.begin(31250);
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);
    usbMIDI.setHandleRealTimeSystem(RealTimeSystem);
    }

    void loop() {
    usbMIDI.read();
    }

    void RealTimeSystem(byte realtimebyte) {
    if(realtimebyte == 248) {
    Serial1.write(248);//pin1 =transmit
    Serial2.write(248);//pin10 =transmit
    Serial3.write(248);// pin8 =transmit
    }}

  7. #7
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    Thanks. I'm actually trying to go the opposite direction though. I want the MIDI out from my drum pad to run into the MIDI IN connector I have set up on pin 7 of the Teensy. Then I want the Teensy to send that MIDI info through usbMIDI to the computer.

  8. #8
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    959
    Yep, I got that. My point was to perhap explore using serialx.begin() in setup and serialx.read() in your loop code. Sorry, I should have been more obvious.
    Last edited by mortonkopf; 12-21-2015 at 02:48 PM. Reason: typo

  9. #9
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    Ok thanks. Am I getting any closer with this...
    Code:
    #include "Arduino.h"
    #include <MIDI.h>
    
    void noteoff(byte channel, byte note, byte velocity){
      Serial.println("note OFF");
    }
    
    void noteon(byte channel, byte note, byte velocity){
      Serial.println("note ON");
    }
    
    void setup() {
      Serial.begin(31250); 
      Serial3.begin(31250);
      MIDI.begin(MIDI_CHANNEL_OMNI);
      MIDI.setHandleNoteOff(noteoff);
      MIDI.setHandleNoteOn(noteon) ;
    }
    
    void loop(){
      Serial3.read();
    }

  10. #10
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    959
    And print the incoming to the serial terminal to see what you are reading. perhaps something along the lines of
    void loop(){
    Serial.println (Serial3.read());
    }

  11. #11
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    959
    I ran a test on the three serial options for midi read this evening, and yes, serial3.read() gives different output to the serial monitor than Serial1 and serial2 read prints to serial monitor. However, this may be because I did not put proper hardware in, no resistors etc, not as should be as described at https://www.pjrc.com/teensy/td_libs_MIDI_sch.gif
    With the addition of: Teensy 3.0: Use two 47 ohm resistors on MIDI OUT, with the pin 4 resistor to +3.3 volts. For MIDI IN, connect the 270 ohm resistor to +3.3 volts.

    However, I did get input to the teensy 3 from serial3.read(), it wasn't totally empty. All I used as a test was:

    Code:
    #include <MIDI.h>
    
    void setup() {
    Serial.begin(31250); 
    Serial3.begin(31250);
     MIDI.begin();
    }
    
    void loop() {
      Serial.print(Serial3.read());
    }
    Last edited by mortonkopf; 12-21-2015 at 10:04 PM.

  12. #12
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    Thanks for doing that. I tried "Serial.print(Serial3.read());" too and I just got "-1" streaming across the page. Then I tried this...
    Code:
      if (Serial3.read != -1){
        Serial.print("MIDI");
      }
    Still can't get notes to register. You say Serial1 and Serial2 work ok though?

  13. #13
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    959
    Quote Originally Posted by monkeybiscuits View Post
    Still can't get notes to register. You say Serial1 and Serial2 work ok though?
    Yes, i have a stream of input coming from Serial1, and I use serial1 as a midi input for my Korg monotron project to convert MIDI Din to CV. Looks like you may need to check how its wired up, even the little things, like tx -> rx.

  14. #14
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    Final answer...YES, Teensy 3.x (and presumably LC) can receive MIDI on all three serial ports. I moved the MIDI input to pin 0 and, when that wasn't working, I knew I had some wires crossed on my MIDI circuit. I sorted that out and got it working on Serial1 but I figured it would be more noteworthy if I actually got it working on Serial3. So I move it BACK and after changing line #44 in midi.h to this:
    Code:
    #define USE_SERIAL_PORT         Serial3
    This test code works fine.
    Code:
    #include "Arduino.h"
    #include <MIDI.h>
    
    void noteon(byte i, byte j, byte k){
      Serial.println("note ON");
    }
    
    void setup() {
      Serial.begin(31250);
      MIDI.begin(MIDI_CHANNEL_OMNI);
      MIDI.setHandleNoteOn(noteon) ;
    }
    
    void loop(){
      MIDI.read();
    }
    Thanks for sticking with me on this. It's the last part of this prototype I needed to get working before I could have a proper PCB made and be done with this hairball.

  15. #15
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,112
    Note, the Teensy 3.1/3.2 has 8 byte FIFOs on Serial1/Serial2 (none on Serial3). The LC has no FIFOs on any serial port. If you are receiving a lot of input, I would expect the FIFOs on Serial1/Serial2 to help avoid losing data.

    I don't know if MIDI has RTS/CTS support, but if so, recent releases allow you to add a pin for hardware flow control. Note, I haven't used it myself, I just remember seeing the announcements for it.

    If you still have the original Teensy 3.0, it only has an 8 byte FIFO on Serial1.

  16. #16
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    Ok. I plan to go ahead and use Serial1 for the MIDI input on the final layout anyway. But that's good info.

  17. #17
    Member
    Join Date
    Dec 2014
    Location
    Japan
    Posts
    37
    MIDI in works fine but the signal seems to be jumping to adjacent pins. Down on pin 7 it was between the clock and latch pins of my serial display causing all kinds of weird things to happen. I figured I'd just fiddled with pin 7 one too many times so I moved MIDI in back up to pin 0. Pin 1 is a switch using INPUT_PULLUP and Bounce. Now every time I send a note to pin 0, the input on pin 1 also gets triggered.

    UPDATE: I just answered my own question. It was a simple oversight. If you want to use a TX pin for something other than MIDI output, you need to tell MIDI.h
    Code:
    #define COMPILE_MIDI_IN         1           // Set this setting to 1 to use the MIDI input.
    #define COMPILE_MIDI_OUT        0           // Set this setting to 1 to use the MIDI output. 
    #define COMPILE_MIDI_THRU       0           // Set this setting to 1 to use the MIDI Soft Thru feature
    Last edited by monkeybiscuits; 12-24-2015 at 11:16 AM. Reason: UPDATE: Working fine now.

Posting Permissions

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