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

Thread: Teensy 4.0 Not Receiving USB MIDI info

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    1

    Teensy 4.0 Not Receiving USB MIDI info

    Hello!

    I'm new around here, just trying to figure out what I thought was going to be a quick project.

    I'm attempting to use a Teensy 4.0 to build out a MIDI interface. Running into some issues with this though. I have two Teensy 4.0s and it seems I cannot receive any messages from any of my USB enabled MIDI devices while using a T4 attached via USB to my MBP running the latest macOS. I tried routing in the Audio MIDI Setup but was unable to route my sequencer or keyboard to my Teensy in a way that would result in any messages being printed via InputRead, the basic script. I am using Serial + MIDI mode in tools. I'm running a basic script but I've attached the code here. It receives no errors when compiling or running to my knowledge. Please tell me if I'm missing any info that may track down the issue.

    Edit: upon reread to be more clear: I was using one T4 at a time but neither were working. I'm convinced I have something in my setup wrong but I can't figure out what.

    Code:
    /* Receive Incoming USB MIDI by reading data.  This approach
       gives you access to incoming MIDI message data, but requires
       more work to use that data.  For the simpler function-based
       approach, see InputFunctionsBasic and InputFunctionsComplete.
    
       Use the Arduino Serial Monitor to view the messages
       as Teensy receives them by USB MIDI
    
       You must select MIDI from the "Tools > USB Type" menu
    
       This example code is in the public domain.
    */
    
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
      // usbMIDI.read() needs to be called rapidly from loop().  When
      // each MIDI messages arrives, it return true.  The message must
      // be fully processed before usbMIDI.read() is called again.
      if (usbMIDI.read()) {
        processMIDI();
      }
    }
    
    void processMIDI(void) {
      byte type, channel, data1, data2, cable;
    
      // fetch the MIDI message, defined by these 5 numbers (except SysEX)
      //
      type = usbMIDI.getType();       // which MIDI message, 128-255
      channel = usbMIDI.getChannel(); // which MIDI channel, 1-16
      data1 = usbMIDI.getData1();     // first data byte of message, 0-127
      data2 = usbMIDI.getData2();     // second data byte of message, 0-127
      cable = usbMIDI.getCable();     // which virtual cable with MIDIx8, 0-7
    
      // uncomment if using multiple virtual cables
      //Serial.print("cable ");
      //Serial.print(cable, DEC);
      //Serial.print(": ");
    
      // print info about the message
      //
      switch (type) {
        case usbMIDI.NoteOff: // 0x80
          Serial.print("Note Off, ch=");
          Serial.print(channel, DEC);
          Serial.print(", note=");
          Serial.print(data1, DEC);
          Serial.print(", velocity=");
          Serial.println(data2, DEC);
          break;
    
        case usbMIDI.NoteOn: // 0x90
          Serial.print("Note On, ch=");
          Serial.print(channel, DEC);
          Serial.print(", note=");
          Serial.print(data1, DEC);
          Serial.print(", velocity=");
          Serial.println(data2, DEC);
          break;
    
        case usbMIDI.AfterTouchPoly: // 0xA0
          Serial.print("AfterTouch Change, ch=");
          Serial.print(channel, DEC);
          Serial.print(", note=");
          Serial.print(data1, DEC);
          Serial.print(", velocity=");
          Serial.println(data2, DEC);
          break;
    
        case usbMIDI.ControlChange: // 0xB0
          Serial.print("Control Change, ch=");
          Serial.print(channel, DEC);
          Serial.print(", control=");
          Serial.print(data1, DEC);
          Serial.print(", value=");
          Serial.println(data2, DEC);
          break;
    
        case usbMIDI.ProgramChange: // 0xC0
          Serial.print("Program Change, ch=");
          Serial.print(channel, DEC);
          Serial.print(", program=");
          Serial.println(data1, DEC);
          break;
    
        case usbMIDI.AfterTouchChannel: // 0xD0
          Serial.print("After Touch, ch=");
          Serial.print(channel, DEC);
          Serial.print(", pressure=");
          Serial.println(data1, DEC);
          break;
    
        case usbMIDI.PitchBend: // 0xE0
          Serial.print("Pitch Change, ch=");
          Serial.print(channel, DEC);
          Serial.print(", pitch=");
          Serial.println(data1 + data2 * 128, DEC);
          break;
    
        case usbMIDI.SystemExclusive: // 0xF0
          // Messages larger than usbMIDI's internal buffer are truncated.
          // To receive large messages, you *must* use the 3-input function
          // handler.  See InputFunctionsComplete for details.
          Serial.print("SysEx Message: ");
          printBytes(usbMIDI.getSysExArray(), data1 + data2 * 256);
          Serial.println();
          break;
    
        case usbMIDI.TimeCodeQuarterFrame: // 0xF1
          Serial.print("TimeCode, index=");
          Serial.print(data1 >> 4, DEC);
          Serial.print(", digit=");
          Serial.println(data1 & 15, DEC);
          break;
    
        case usbMIDI.SongPosition: // 0xF2
          Serial.print("Song Position, beat=");
          Serial.println(data1 + data2 * 128);
          break;
    
        case usbMIDI.SongSelect: // 0xF3
          Serial.print("Sond Select, song=");
          Serial.println(data1, DEC);
          break;
    
        case usbMIDI.TuneRequest: // 0xF6
          Serial.println("Tune Request");
          break;
    
        case usbMIDI.Clock: // 0xF8
          Serial.println("Clock");
          break;
    
        case usbMIDI.Start: // 0xFA
          Serial.println("Start");
          break;
    
        case usbMIDI.Continue: // 0xFB
          Serial.println("Continue");
          break;
    
        case usbMIDI.Stop: // 0xFC
          Serial.println("Stop");
          break;
    
        case usbMIDI.ActiveSensing: // 0xFE
          Serial.println("Actvice Sensing");
          break;
    
        case usbMIDI.SystemReset: // 0xFF
          Serial.println("System Reset");
          break;
    
        default:
          Serial.println("Opps, an unknown MIDI message type!");
      }
    }
    
    
    void printBytes(const byte *data, unsigned int size) {
      while (size > 0) {
        byte b = *data++;
        if (b < 16) Serial.print('0');
        Serial.print(b, HEX);
        if (size > 1) Serial.print(' ');
        size = size - 1;
      }
    }

  2. #2
    Have you definitely get your MIDI routing right on your Mac? Presumably your code is just an example so there's no reason why it shouldn't run.

Posting Permissions

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