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

Thread: Passing midi data from MidiUSB to Midi out on TX pin (Teensy 3.2)

  1. #1
    Junior Member
    Join Date
    Jun 2018
    Posts
    7

    Passing midi data from MidiUSB to Midi out on TX pin (Teensy 3.2)

    Hi everyone,
    First time poster, long time lurker here. I haven't found a thread on this specific issue yet, so I appreciate any help you all can give!

    I am working on a project where (among other things) I am using a Teensy 3.2 to receive Midi data through both/either USB Midi, or a 5 Din Midi connector on the RX1 pin, and pass it through to a separate synth chip attached to the TX1 pin. As of now, I can plug a midi controller into the 5din connector and it passes the midi data through from RX1 to TX1 like a dream with like 5 lines of code:

    Code:
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
      MIDI.begin();
    }
    
    void loop() { 
    if (MIDI.read())
      {
        MIDI.send(MIDI.getType(),
                  MIDI.getData1(),
                  MIDI.getData2(),
                  MIDI.getChannel());
      }
    }
    Great!

    However, I can't for the life of me get midi data coming in from USB Midi, to output to the TX1 pin. I have tried using basically the same code, which throws a compile error:

    Code:
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
      MIDI.begin();
      usbMIDI.begin();
    }
    
    void loop() {
    // RX1 to TX1 
    if (MIDI.read())
      {
        MIDI.send(MIDI.getType(),
                  MIDI.getData1(),
                  MIDI.getData2(),
                  MIDI.getChannel());
      }
    }
    //USB Midi to TX1
    if (usbMIDI.read())
      {
        MIDI.send(usbMIDI.getType(),
                  usbMIDI.getData1(),
                  usbMIDI.getData2(),
                  usbMIDI.getChannel());
      }
    }
    I have also tried using the method shown on the usbMidi library page, where you set handlers in setup (such as "usbMIDI.setHandleNoteOff(myNoteOff);") and have a separate loop that triggers for various note events. Those separate loops will compile and work fine for just about anything EXCEPT sending midi data to TX1 it seems. For example, this is fine:

    Code:
    void myControlChange(byte channel, byte control, byte value) {
      Serial.print("Control Change, ch=");
      Serial.print(channel, DEC);
      Serial.print(", control=");
      Serial.print(control, DEC);
      Serial.print(", value=");
      Serial.print(value, DEC);
      Serial.println();
    }
    But neither of these will work:

    Code:
    void myNoteOn(byte channel, byte note, byte velocity) {
        MIDI.send(usbMIDI.getType(),
                  usbMIDI.getData1(),
                  usbMIDI.getData2(),
                  usbMIDI.getChannel());
    }
    
    void myNoteOff(byte channel, byte note, byte velocity) {
      MIDI.send(0x80, note, velocity, 1); 
    }
    I have confirmed that I have the most up-to-date versions of both the Arduino IDE, and Teensyduino. Does anyone have a hot tip on how I can read data coming from usbMidi and use good 'ole MIDI.send on it?
    Thanks, I really appreciate any input!

    -Wesley

  2. #2
    Senior Member
    Join Date
    Jan 2017
    Location
    Maastricht
    Posts
    170
    There's an example of a 3 x 3 midi interface that does what you want (Interface_3x3). Look in the Arduino IDE under File > Examples > Teensy > USB_MIDI.

  3. #3
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    295
    The following code compiles, not tested with midi

    Code:
    #include <MIDI.h>
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
      MIDI.begin();
      usbMIDI.begin();
    }
    
    void loop() {
    // RX1 to TX1 
    if (MIDI.read())
      {
        MIDI.send(MIDI.getType(),
                  MIDI.getData1(),
                  MIDI.getData2(),
                  MIDI.getChannel());
      }
    
    //USB Midi to TX1
    if (usbMIDI.read())
      {
        MIDI.send((midi::MidiType)usbMIDI.getType(),
                  usbMIDI.getData1(),
                  usbMIDI.getData2(),
                  usbMIDI.getChannel());
      }
    }

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,925
    The example MidiUSB.ino has this line not shown above - updated for a second usbMIDI connect: MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, MIDI);

    Also if the verbose text of "throws a compile error:" were shown it might point to the source of the problem.

  5. #5
    Junior Member
    Join Date
    Jun 2018
    Posts
    7
    Oh wow, thanks for the help everyone. I feel a tad embarrassed at missing the 3x3 code example. Works like a charm. Thanks for the help.
    /thread
    -Wesley

Posting Permissions

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