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

Thread: MIDI wont work on teensy, works on arduino?

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    12

    MIDI wont work on teensy, works on arduino?

    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
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    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?

  3. #3
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    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

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    The code looks good. Maybe a hardware problem? Can you show up (photos) how it's actually wired up?

  5. #5
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    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.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    Very likely to be a simple misunderstanding or mistake in how the wires connect. Can't tell without photos.

  7. #7
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    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

    Click image for larger version. 

Name:	IMG_1662.jpg 
Views:	83 
Size:	194.4 KB 
ID:	12004

    Click image for larger version. 

Name:	IMG_1663.jpg 
Views:	73 
Size:	185.9 KB 
ID:	12005

  8. #8
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    any more info I can provide? has anyone had any issues with the teensy not responding to midi serial data on pin 0?

  9. #9
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    78
    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.
    Click image for larger version. 

Name:	Untitled.png 
Views:	154 
Size:	6.8 KB 
ID:	12009
    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 by Revalogics; 11-07-2017 at 05:09 AM.

  10. #10
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    985
    You're pulling up to 5 V on a T3.6?

  11. #11
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    78
    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?

  12. #12
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    985
    Sorry.... didn't read carefully.

  13. #13
    The code looks good. Maybe a hardware problem?

  14. #14
    Junior Member
    Join Date
    Nov 2017
    Posts
    12
    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

  15. #15
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    841
    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 by mortonkopf; 11-12-2017 at 09:04 AM.

  16. #16
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    78
    Quote Originally Posted by mortonkopf
    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) {}

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    Quote Originally Posted by tjm56 View Post
    OK - here is my set up using a teensy 3.2, as well as the setup using the arduino uno.
    Which optocoupler chip is that in the photo? I see 8 pins. Maybe a 6N138?

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    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:


  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    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.

  20. #20
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,788
    I think that an oscilloscope, connected to the RX pin, will allow to solve that problem quickly.

Posting Permissions

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