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

Status
Not open for further replies.
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
 
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.
 
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());
  }
}
 
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.
 
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
 
Status
Not open for further replies.
Back
Top