View Full Version : Teensy 2 MDI Question

12-28-2013, 06:58 PM

Was just trying the basic to see output using the following program -

#include <Arduino.h>
#include <MIDI.h>

Basic I/O MIDI tutorial
by Franky

#define LED 13 // LED pin on Arduino board

void setup() {
pinMode(LED, OUTPUT);
MIDI.begin(4); // Launch MIDI with default options
// input channel is set to 4

void loop() {
if (MIDI.read()) {
digitalWrite(LED,HIGH); // Blink the LED
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

I recently changed the pin back to 13 to try the program on Teensy 3.1 and added the include statements as suggested in another post but same results. Never see the led change. I am using a MAC so was unsure if I need to set something up? Would appreciate any suggestions. Thank you.

Cheers, Michael

12-29-2013, 04:55 AM
Which version of the MIDI library are you using?
What circuitry are you using with this?
Could you link to the 'another post'?

12-29-2013, 02:35 PM
I believe the version of MIDI.h is version 3.2. And no circuit, thought I could just sent the note to the teensy and blink the led? I am new to this so am quite sure I am doing something wrong. And apologies I will need to search for the post. Thank you for the reply.

Cheers, Michael

12-30-2013, 08:30 AM
Your sketch is reading from circuitry that isn't there; so

if (MIDI.read()) {
is false, so doesn't get executed.

When you say 'send the note to the teensy' how are you sending it?

12-30-2013, 07:46 PM
Are you using MIDI 3.2 downloaded from sourceforge, or the copy from PJRC.

The PJRC one has a couple extra lines of code, so MIDI will use "Serial1" instead of "Serial". Look for it near the comments in the code which explain you should set it to the port you want to use.

On Teensy, "Serial" is the USB virtual serial. If you use the unmodified copy of MIDI 3.2, MIDI.read() will look for bytes to arrive on the USB virtual serial. Obviously you want it to look for bytes arriving on the real serial port.

12-30-2013, 07:48 PM
The MIDI 3.2 library is for regular MIDI with the 5 pin DIN connector, and usually an opto-isolator circuit between the DIN connector and the RX1 pin.

If you want to receive MIDI from USB, you would set Tools > USB Type to MIDI and use this instead:


12-30-2013, 09:24 PM
Thank you both for your help, I now have the led blinking. Am using the test program from Pd-extended and have the teensy set as input an output. I used the program from the web page Paul supplied and seems I needed the usbMidi command. And yes for now I am just going through USB. Thank you again.

Cheers, Michael