MIDI Basic_IO example problem

I'm trying to run the MIDI Library's Basic_IO example on a Teensy 4.1.
On the Arduino IDE "Tools / USB Type" menu I've selected "Serial + MIDI".
I modified the sketch Loop so that it continually sends notes and flashes the LED on one second intervals.
I have a MIDI Monitor program running on my PC.
The Monitor recognizes the "Teensy MIDI" but does not see any messages coming from it. I also tried it with "Serial + MIDI4" selected.
The Monitor responds to a keyboard I have also connected, so I know it is working correctly.
I'll post the sketch code below.
Any ideas?

Here is the sketch code:
#include <MIDI.h>
// Simple tutorial on how to receive and send MIDI messages.
// Here, when receiving any message on channel 4, the Arduino
// will blink a led and play back a note for 1 second.
MIDI_CREATE_DEFAULT_INSTANCE();
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(4); // Launch MIDI and listen to channel 4
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(42, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(58, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(58, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
void loop()
{
//if (MIDI.read()) // (Loop continually) If we have received a message
{
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(42, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(58, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(58, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
}
 
Your code is probably working but sending on TX1.

usbMIDI examples are found in File>Examples>Teensy>USB_MIDI
 
1705279546987.png
 
Making the same observation/recommendation as @MatrixRat, your current sketch is initializing the default MIDI interface by way of the call to MIDI_CREATE_DEFAULT_INSTANCE(). Following this, it is thus sending the canned MIDI messages (MIDI.sendNoteOn() & MIDI.sendNoteOff()) over that same default MIDI interface. This interface operates over standard Serial Port 1 (RX1 on PIN 0 & TX1 on PIN 1). If you're trying to monitor these messages from your sketch as written, you'll need to somehow connect something to the RX1/TX1 pins.

Alternately, if you'd like to monitor these types of messages with your PC (which is presumably connected to/thru the microUSB interface on the Teensy), you'll need to change your canned MIDI messages to usbMIDI.sendNoteOn() & usbMIDI.sendNoteOff(). There is no special and/or additional initialization needed to make use of the usbMIDI interface (other than compiling as Serial + MIDI, as you have already done).

Mark J Culross
KD5RXT
 
Back
Top