MIDI wont work on teensy, works on arduino?

Status
Not open for further replies.

tjm56

Member
Hoping to get some help as to why i cant get MIDI to work with the teensy. I have it working with my arduino uno, when I'm using teensyduino IDE I change the usb type to MIDI. Any ideas on why it works on arduino and not teensy? thanks

heres the code I'm trying to test out:

Code:
#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
  // OMNI sets it to listen to all channels.. MIDI.begin(2) would set it 
  // to respond to notes on channel 2 only.
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function you want to call when a NOTE ON command
  // is received. In this case it's "MyHandleNoteOn".
  MIDI.setHandleNoteOff(MyHandleNoteOff); // This command tells the Midi Library 
  // to call "MyHandleNoteOff" when a NOTE OFF command is received.
}

void loop() { // Main loop
  MIDI.read(); // Continuously check if Midi data has been received.
}

// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,HIGH);  //Turn LED on
}

// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,LOW);  //Turn LED off
}
 
You're talking of "change the usb type to MIDI", but this code looks like the MIDI library for regular serial (big 5 pin DIN connector) MIDI, not USB MIDI.

How are you really connecting the MIDI signal?
 
You're talking of "change the usb type to MIDI", but this code looks like the MIDI library for regular serial (big 5 pin DIN connector) MIDI, not USB MIDI.

How are you really connecting the MIDI signal?

Midi is connected via a 5 pin din + optocoupler setup
 
The code looks good. Maybe a hardware problem? Can you show up (photos) how it's actually wired up?

I can get some pictures later, however, when I hook up the midi input circuit to an arduino uno it works as expected, but when I swap out the arduino for a teensy (3.6 and LC) it doesnt work at all.

I have the output of the midi input circuit going to RX pin 0 on the teensy.
 
Very likely to be a simple misunderstanding or mistake in how the wires connect. Can't tell without photos.

OK - here is my set up using a teensy 3.2, as well as the setup using the arduino uno. The bottom yellow wire is going to pin 0 on the teensy, orange wire is to the groun rails of the breadboard, other yellow is to the power rail. Again, its working with the arduino but not the teensy

IMG_1662.jpg

IMG_1663.jpg
 
any more info I can provide? has anyone had any issues with the teensy not responding to midi serial data on pin 0?
 
Hi, I've been using Teensy 3.6 every Sunday to convert MIDI to usbMIDI, and it has been working for months now, without any issues on the Teensy part.
Untitled.png
I followed this schematic based on this MIDI Library Page, except I have both the 220 and 270 Ω resistors replaced by 237 Ω resistor (which I only have lying around by the time I veroboarded my circuit). Diode is 1N4148, and optocoupler is PC900V from SHARP.

By the way, PC900V and the pullup resistor is connected to 3.3V, not to 5V, because doing so will damage my Teensy 3.6.

My project accepts MIDI input (5 pin MIDI), usbMIDI input (both from the PC side and USB host port), usbMIDI out (PC side), audio in and out, DMX out (with sound-active operation). Other things included are 8 pots, 2 encoders, 1 button, a 20x4 LCD, 8 RGB LEDs, and 5 regular LEDs, powered by 74HC595, all running smoothly from a 1,944 lines long sketch (not kidding).

I'm looking forward to expand this project a little bit more by adding drum trigger support (so it will become a E-drum controller), and 16 pads (that I can hit to launch sounds and effects).
 
Last edited:
As I already mentioned:

By the way, PC900V and the pullup resistor is connected to 3.3V, not to 5V, because doing so will damage my Teensy 3.6.

Wait, is it me or is it him? :D
 
the hardware is the same for the set up with the arduino (which I have confirmed and working) and the teensy (which will not accept midi data over serial input on pin 0). I will try pulling up the pin 0 to 3.3v like you have done, thanks for the tip Revalogics! thanks for all the responses everyone
 
does it require a Serial1.begin(31250) in setup() for using rxtx on pins0 and1, or a #define USE_SERIAL_PORT Serial1 in the .h file?

to test the hardware, you can run a simple sketch that just reads from serial1 and prints to the IDE monitor.
 
Last edited:
mortonkopf said:
does it require a Serial1.begin(31250) in setup() for using rxtx on pins0 and1, or a #define USE_SERIAL_PORT Serial1 in the .h file?

Those are not really needed, as they are defined inside the library (Serial1 is used as default). The following should work:

// global scope
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

// inside setup()
MIDI.setHandleNoteOff(MIDI_onNoteOff);
MIDI.setHandleNoteOn(MIDI_onNoteOn);
MIDI.setHandleControlChange(MIDI_onControlChange);
MIDI.setHandleProgramChange(MIDI_onProgramChange);
MIDI.setHandlePitchBend(MIDI_onPitchChange);
MIDI.begin(MIDI_CHANNEL_OMNI);

// inside loop()
MIDI.read();

// callback functions
void MIDI_onNoteOff(byte channel, byte note, byte velocity) {}
void MIDI_onNoteOn(byte channel, byte note, byte velocity) {}
void MIDI_onControlChange(byte channel, byte control, byte value) {}
void MIDI_onProgramChange(byte channel, byte program) {}
void MIDI_onPitchChange(byte channel, int pitch) {}
 
I tested just now using a 6N136 optocoupler (which I happen to have in my parts bin). It definitely works. Here's a quick video of the test:

 
I don't know why your circuit works with Uno but fails on Teensy. Perhaps the resistor values are too low and the logic level is just barely able to be seen by 5V Uno, but not by 3.3V Teensy?

At least this test can confirm the code you posted does indeed work with Teensy 3.2. The problem is almost certainly hardware, even though it works on Uno.
 
I can confirm, I had the same issue and fixed this by using a larger resistor between the 6N138 and the teensy RX pin. I had a 220 which worked for the arduino, but was not working for the teensy 3.2. When I replaced the 220 with a 470 I got a clear signal from the midi input.
 
Status
Not open for further replies.
Back
Top