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

Thread: Help me understand where I'm wrong with this Midi DIN out

  1. #1
    Member garubi's Avatar
    Join Date
    Sep 2016
    Location
    Modena, Italy, EU
    Posts
    43

    Help me understand where I'm wrong with this Midi DIN out

    I'm trying to make a working Midi DIN output but after several hours checking, debugging etc... I can't get it sending anyting...
    so I'm asking your help to understand where I'm failing...

    I'm using a Teensy LC. Arduino 1.8.2. Teensyduino 1.36

    the test sketch I'm using is this:
    Code:
    #include <MIDI.h>
    
    #include <Bounce.h>  // Bounce library makes button change detection easy
    #define LED 13       // LED pin on Arduino board
    Bounce button1 = Bounce(12, 5);  // 5 = 5 ms debounce time
    
    void setup() {
      pinMode(12, INPUT_PULLUP);
      pinMode(LED, OUTPUT);
      MIDI.begin(MIDI_CHANNEL_OMNI);
    }
    
    void loop() {
      button1.update();
    
      // Note On messages when each button is pressed
      if (button1.fallingEdge()) {
    //    usbMIDI.sendNoteOn(60, 99, 1);  // 60 = C4
        MIDI.sendNoteOn(60, 99, 1);
         digitalWrite(LED,HIGH);     // Blink the LED
      }
    
      // Note Off messages when each button is released
      if (button1.risingEdge()) {
      //  usbMIDI.sendNoteOff(60, 0, 1);  // 60 = C4
           MIDI.sendNoteOff(60, 0, 1);
    
         digitalWrite(LED,LOW);     // Blink the LED
      }
    
    }
    If I push the button, the Led lights, when I release it the Led turns off, as expected.
    If I use usbMidi I get Note On and Note Off accordingly to the buttun press and release.
    If I try with MIDI library nothing is (apparently) sent.

    I tried using Usb Type Serial, Midi, Serial+MIDI but nothing changed.

    Here are some pictures of the circuit on the breadbord.
    The resistors are 47 Ohm.

    Click image for larger version. 

Name:	20170426_230404.jpg 
Views:	96 
Size:	117.9 KB 
ID:	10422
    Click image for larger version. 

Name:	20170426_230415.jpg 
Views:	98 
Size:	92.2 KB 
ID:	10423
    Click image for larger version. 

Name:	20170426_230557.jpg 
Views:	78 
Size:	111.7 KB 
ID:	10424

    I'm sure that's something very obvious that's wrong... but I can't see it... can you help me?

    Thanks in advance!

    Stefano

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,317
    Pins 0 and 1 are Serial1. By default the MIDI library uses Serial. Edit the library file ..\arduino-1.8.2-1.3.6\hardware\teensy\avr\libraries\MIDI\MIDI.h and modify this line
    Code:
    #define USE_SERIAL_PORT         Serial      // Change the number (to Serial1 for example) if you want
    to use Serial1.

    Pete

  3. #3
    Member garubi's Avatar
    Join Date
    Sep 2016
    Location
    Modena, Italy, EU
    Posts
    43

    Unhappy

    Quote Originally Posted by el_supremo View Post
    Pins 0 and 1 are Serial1. By default the MIDI library uses Serial. Edit the library file ..\arduino-1.8.2-1.3.6\hardware\teensy\avr\libraries\MIDI\MIDI.h and modify this line
    Code:
    #define USE_SERIAL_PORT         Serial      // Change the number (to Serial1 for example) if you want
    to use Serial1.

    Pete
    Hi Pete,
    thank you!

    I changed that line but still nothing happens...

    Maybe I have to "set" the USB type to something different? I tried with Serial, Midi, and Serial + Midi... but no luck
    Or maybe is a wiring problem... but really with such a simple circuit I can't see where it could be wrong...
    I even tried to change the Midi plug pins...

    btw I think that changing the #define in midi.h could not be necessary because I see that some lines down there is an #if block that should redefine it if on Teensy... isn't it?:
    Code:
    #define USE_SERIAL_PORT         Serial1      // 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

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,317
    #if block that should redefine it if on Teensy... isn't it?
    You're right.

    I think you have pins 4 and 5 wired backwards. In photo 3, pin 4 is on the right and should be the pullup to 3v3.
    See the photo below the circuit diagram here

    BTW. The code should work when compiled with USB type Serial.
    Pete
    Last edited by el_supremo; 04-27-2017 at 03:08 PM.

  5. #5
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,341
    I was going to say the polarity on the MIDI DIN output is the most likely source of wiring error and a quick look at yours this morning had me thinking you have this reversed.

    The positive source should be on the right-hand-side of the DIN connector (female) as you look at it's face... looks like it's on the left on yours

  6. #6
    Member garubi's Avatar
    Join Date
    Sep 2016
    Location
    Modena, Italy, EU
    Posts
    43

    Unhappy Swapped pins but still nothing transmitted

    Thank you for pointing out the reversed pin error...
    I swapped the two pins but still nothing is transmitted
    I stripped down the script and the circuit too, to be sure that nothing interferes here.
    The LED blinks as expected.
    The Teensy is setup as Serial

    I checked for continuity and voltage (I only have a digital multimeter)... all looks like ok, just on the 3v3 pin I have lightly less than 3v3, around 3v26, wondering if such a little variation can cause problems.
    Also, as you can see I connected to the 3v pin near the usb connector, should I use the 3v pin that's on the short side oppopsite to the usb connector?
    For my tests I used both a real keyboard with MIDI in, and another pc with MIDI-OX (in this case tried with 2 different interfaces)

    Any other suggestion will be appreciated

    Here the new code and the new pictures:
    Code:
    #include <MIDI.h>
    
    #define LED 13       // LED pin on Arduino board
    
    void setup() {
      pinMode(LED, OUTPUT);
      MIDI.begin(MIDI_CHANNEL_OMNI);
    }
    
    void loop() {
        //    usbMIDI.sendNoteOn(60, 99, 1);  // 60 = C4
        MIDI.sendNoteOn(60, 127, 1);
        digitalWrite(LED, HIGH);    // Blink the LED
        delay(1000);
        
        //  usbMIDI.sendNoteOff(60, 0, 1);  // 60 = C4
        MIDI.sendNoteOff(60, 0, 1);
        digitalWrite(LED, LOW);    // Blink the LED
        delay(1000);
    }
    Click image for larger version. 

Name:	20170428_085232.jpg 
Views:	51 
Size:	99.4 KB 
ID:	10428

    Click image for larger version. 

Name:	20170428_085249.jpg 
Views:	39 
Size:	111.4 KB 
ID:	10429

    Click image for larger version. 

Name:	20170428_085348.jpg 
Views:	44 
Size:	119.9 KB 
ID:	10430

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,878
    What's that socket under the teensy ? Are its pins long enough to connect to the breadboard ? Did you try it without that socket ?
    And..shouldn't MIDI be 5 Volt ? - I don't know MIDI!
    Last edited by Frank B; 04-28-2017 at 09:55 AM.

  8. #8
    Member garubi's Avatar
    Join Date
    Sep 2016
    Location
    Modena, Italy, EU
    Posts
    43
    Hi Frank,

    well it's just an IC socket... I used Teensy mounted on it for other testing (5 analog input, some buttons etc) and it had no problem.
    I have to add that I checked the voltage at the end of the green wire (coming out from pin1, serial TX) and I remember I've got something around 3v so I implicitly deduced that the Teensy pin's were connecting.

    Anyway, you hit a good point: when I'll go home (now I'm in the lunch break at the office) I'll try removing the socket and also moving the Teensy to another place in the breadbord.

    For the 5v question: I see here (just below the MIDI schematic) that on Teensy 3 we have to use 3v.
    So, since I'm using Teensy LC I assumed that the same 3v would apply to Teensy LC.
    But maybe I'm wrong... can anyone confirm this?

    Thank you a lot for your help!

    I'll keep trying...

    Stefano
    Last edited by garubi; 04-28-2017 at 12:01 PM. Reason: typos

  9. #9
    Member garubi's Avatar
    Join Date
    Sep 2016
    Location
    Modena, Italy, EU
    Posts
    43

    Smile [solved!]

    I resolved the issue... thanks to all of you!

    As often happens it was a stupid thing: a broken jumper...
    and obviously the inverted pins in the MIDI connector...

    Now I can go ahead with my Drawbars MIDI controller... until the next problem arises

    Stefano
    Last edited by garubi; 04-28-2017 at 03:41 PM.

Posting Permissions

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