Uploading code to teensy...MIDI.h header not found

Hi all.

I am getting my feet wet and got wet.

I am trying this first attempt to get a sound.

#include <MIDI.h>
void setup() {
// put your setup code here, to run once:
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
/////begin(); I tried this instead of the pervious cmd and it wont work either
}

void loop() {
// put your main code here, to run repeatedly:
// Send note 42 with velocity 127 on channel 1
MIDI.sendNoteOn(42, 127, 1);

// Read incoming messages
MIDI.read();
}



MIDI.h is not found and I dont know where to get it.

I was told begin(); is a switch to turn on the midi communication. I am using a teensy4.1 a host cable and a compliant wind controller.

Please advise.
Thanks
 
First of all can you enclose your code between CODE tags. You can insert them into your posts using the # button.
It just makes your code easier to read and understand and makes it easier for others to help you.
Code:
#include <MIDI.h>
void setup() {
	// put your setup code here, to run once:
	MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
	/////begin(); I tried this instead of the pervious cmd and it wont work either
}

void loop() {
	// put your main code here, to run repeatedly:
	// Send note 42 with velocity 127 on channel 1
	MIDI.sendNoteOn(42, 127, 1);

	// Read incoming messages
	MIDI.read();
}
If you look at the MIDI examples I am sure you will find some useful info.
I have not used Midi so am not terribly well qualified to help you but I did see some differences between your code and some of the examples given.
See below, from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MIDI\examples\Basic_IO
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
}

void loop()
{
    if (MIDI.read())                    // 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);
    }
}
You also probably need to compile your code with one of the Midi settings.
In Arduino go Tools USB TYPE: and select one of the MIDI varieties.
 
Last edited:
Thank you

I do not know how to do :

compile your code with one of the Midi settings.
In Arduino go Tools USB TYPE: and select one of the MIDI varieties.

Screenshot_20221226_011549.jpg
I installed teensyduino as far as I know.
There is no USB TYPE in tools
 
That menu drop down show the TEENSY is not selected as the 'Board' :>> "Arduino Uno"

Select the Teensy in use from the BOARD menu then the options change:
TeensyTools.png
 
I installed teensyduino as far as I know.
There is no USB TYPE in tools

First you need to click Tools > Board and select Teensyduino > Teensy 4.1.

Arduino IDE changes its menus depending on which board you have selected. In the screenshot, you have Arduino Uno selected. That's why you're not seeing the Teensy-specific menus. It's also why MIDI.h can't be found. The Teensyduino installer added that library for you, but it's in a "platform" folder where Arduino will only use it when you have a Teensy board selected (we do it this way to minimize impacting usage of non-Teensy boards).

Just click the Tools > Boards menu to select Teensy 4.1. This program should work without any errors once you have the correct board selected.
 
Last edited:
Probably also worth mentioning, this program using MIDI.h will try to transmit MIDI messages from circuitry connected to TX1 (pin 1), which works with traditional 5 pin DIN serial MIDI. To make it work, you need to build the MIDI input circuitry described here:

https://www.pjrc.com/teensy/td_libs_MIDI.html

If you instead wanted to receive MIDI messages your PC sends over USB, you can also do that, but you would instead use Tools > USB Type as Defragster mentioned. Then you would use "usbMIDI" in your program, as described here:

https://www.pjrc.com/teensy/td_midi.html

You can get an example by clicking File > Examples > Teensy > USB_MIDI > InputFunctionsBasic.

It's also possible to use MIDI on the USB host port, which would be useful if you have a MIDI instrument or controller which normally plugs into USB on a computer. To plug it into Teensy, you would use this cable.

https://www.pjrc.com/store/cable_usb_host_t36.html

To make MIDI work that way, you would use the USBHost_t36 library. A first example can be found by clicking File > Examples > USBHost_t36 > MIDI > Basic.

But like MIDI.h, you first need to select Teensy in the Tools > Board menu, because Arduino IDE will only give you access to the Teensy-specific USBHost_t36.h when a Teensy board is selected.
 
You said:
They also said to send and recieve midi, I have to build the MIDI input circuitry described here: https://www.pjrc.com/teensy/td_libs_MIDI.html

However I heard (I think in one of your videos) that the teensy 4.1 will transmit midi via usb.

Please help?
Thank you

Posting in multiple places will likely lead to a scattering of related answers. I offered some advice in the <other thread> where you seem to have asked the same question . . .

Mark J Culross
KD5RXT
 
Back
Top