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

Status
Not open for further replies.

garubi

Well-known member
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.

20170426_230404.jpg
20170426_230415.jpg
20170426_230557.jpg

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
 
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
 
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
 
#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:
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
 
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 :eek:

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);
}

20170428_085232.jpg

20170428_085249.jpg

20170428_085348.jpg
 
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:
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:
[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:
Status
Not open for further replies.
Back
Top