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

Thread: Teensy 2 ++ Midi out problem.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    9

    Teensy 2 ++ Midi out problem.

    When using Teensy 2 ++ as a Usb midi device I have no problems.
    I need to send Midi out to another device through the Midi port , I tried this schematic and code :

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

    I used an oscilloscope to see if there was a a signal from the TX pin (pin 3) but found no signal ...

    When I use MIDI.sendNoteOn(note, 100, channel); nothing but usbMIDI.sendNoteOn(note, 100, channel); works fine.

    Thank you

    Brgds

    Kristinn

  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    I have tried using Teensy as Serial and as Midi..

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,312
    I can give it a try here on a Teensy++ 2.0, but only if you post the code you're testing, and specific which version of the library you're using.

  4. #4
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Thanks !

    I am using Midi library 3.2 and just using this code:

    #include <MIDI.h>

    const int channel = 1;

    void setup() {
    MIDI.begin();
    }

    void loop() {
    int note;
    for (note=10; note <= 127; note++) {
    MIDI.sendNoteOn(note, 100, channel);
    delay(200);
    MIDI.sendNoteOff(note, 100, channel);
    }
    delay(2000);
    }

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    And the schematic (only the midi out part) : Click image for larger version. 

Name:	td_libs_MIDI_sch.gif 
Views:	364 
Size:	5.1 KB 
ID:	1029

  6. #6
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    291
    Try to include Arduino.h before including MIDI.h.

    From the MIDI.h file:

    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Thanks for the help , but no change :

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

    const int channel = 1;

    void setup() {
    MIDI.begin();
    }

    void loop() {
    int note;
    for (note=10; note <= 127; note++) {
    MIDI.sendNoteOn(note, 100, channel);
    delay(200);
    MIDI.sendNoteOff(note, 100, channel);
    }
    delay(2000);
    }





    When I change it to :


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

    const int channel = 1;

    void setup() {
    MIDI.begin();
    }

    void loop() {
    int note;
    for (note=10; note <= 127; note++) {
    usbMIDI.sendNoteOn(note, 100, channel);
    delay(200);
    usbMIDI.sendNoteOff(note, 100, channel);
    }
    delay(2000);
    }

    I get the notes played over USB.

    The project I am doing would be so much better if I can avoid USB.

    I appreciate the help

  8. #8
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    I needed to change Serial to Serial1 in Midi.h

    Now it works !!

    Thanks for the help

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,312
    Quote Originally Posted by kiddikiddi View Post
    I needed to change Serial to Serial1 in Midi.h
    Was this code present in Midi.h?

    Code:
    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT         Serial1
    #endif

  10. #10
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Yes , but it was #define USE_SERIAL_PORT Serial.
    Not Serial1.




    Quote Originally Posted by PaulStoffregen View Post
    Was this code present in Midi.h?

    Code:
    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT         Serial1
    #endif

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,312
    Did you get the MIDI library from the page on PJRC, or from the Teensyduino installer, or from the Sourceforge site?

    The copy on Sourceforge doesn't have those extra lines to automatically use Serial1 for Teensy.

  12. #12
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Quote Originally Posted by PaulStoffregen View Post
    Did you get the MIDI library from the page on PJRC, or from the Teensyduino installer, or from the Sourceforge site?

    The copy on Sourceforge doesn't have those extra lines to automatically use Serial1 for Teensy.
    From the PJRC site.

  13. #13
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,312
    The copy on PJRC has this in MIDI.h:

    Code:
    #define USE_SERIAL_PORT         Serial      // Change the number (to Serial1 for example) if you want
                                                                   // to use a different serial port for MIDI I/O.
    Then right after that in MIDI.h, it has this:

    Code:
    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT         Serial1
    #endif
    It's supposed to undefine "Serial" and automatically change it to "Serial1".

    I'm trying to understand why this didn't work for you. Maybe it's a bug that needs to be fixed?

    Could you please take another quick look at your copy of MIDI.h? Does it have both of these, or only the first part? If it was simply missing the 2nd part, then that's the cause. But if that 2nd part is present in your copy, then I have more work to do to figure out why it didn't work as intended.

    I really do want to make sure this problem don't affect anyone else, so if you could please just take another quick look at your copy of MIDI.h and check if it has only 1 or both of these parts, that would really help!

  14. #14
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Quote Originally Posted by PaulStoffregen View Post
    The copy on PJRC has this in MIDI.h:

    Code:
    #define USE_SERIAL_PORT         Serial      // Change the number (to Serial1 for example) if you want
                                                                   // to use a different serial port for MIDI I/O.
    Then right after that in MIDI.h, it has this:

    Code:
    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT         Serial1
    #endif
    It's supposed to undefine "Serial" and automatically change it to "Serial1".

    I'm trying to understand why this didn't work for you. Maybe it's a bug that needs to be fixed?

    Could you please take another quick look at your copy of MIDI.h? Does it have both of these, or only the first part? If it was simply missing the 2nd part, then that's the cause. But if that 2nd part is present in your copy, then I have more work to do to figure out why it didn't work as intended.

    I really do want to make sure this problem don't affect anyone else, so if you could please just take another quick look at your copy of MIDI.h and check if it has only 1 or both of these parts, that would really help!

    In my Midi.h I have :

    #define USE_SERIAL_PORT Serial // Change the number (to Serial1 for example) if you want
    // to use a different serial port for MIDI I/O.

    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT Serial1
    #endif


    So , I donīt understand what caused it ?

  15. #15
    Junior Member
    Join Date
    Oct 2016
    Posts
    10
    Hi, I have the same issue.

    My system (Teensyduino 1.30 supports Arduino versions 1.0.6.11).

    I have downloaded the Midi-Lib from PJRC.
    While the code works below fine for Arduino UNO but it does not work for Teensy 3.2.

    In adddition I have some questions

    1: I have downloaded the MIDI-LIB and added it as Library in Arduino
    The code compiles even when I remove the downloaded Midi-Lib form my computer.
    So, how can I be sure that the downloaded Midi-Lib is used.

    2: I have inserted the line
    #include <Arduino.h>
    but it did not get red color, does it mean, the Lib is not installed ?



    My Code
    ----------
    #include <Arduino.h>
    #include <MIDI.h>
    /*
    Basic I/O MIDI tutorial
    by Franky
    28/07/2009
    */


    void setup() {

    MIDI.begin(4); // Launch MIDI with default options
    // input channel is set to 4
    }

    void loop() {

    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
    }


    My Midi.h
    ----------
    #define USE_SERIAL_PORT Serial // Change the number (to Serial1 for example) if you want
    // to use a different serial port for MIDI I/O.

    // Use Serial1 on all Teensy boards, because Serial is USB virtual serial
    // Arduino.h must be included before MIDI.h to define CORE_TEENSY
    #if defined(CORE_TEENSY)
    #undef USE_SERIAL_PORT
    #define USE_SERIAL_PORT Serial1
    #endif

Tags for this Thread

Posting Permissions

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