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

Thread: Troubleshooting trying to get MIDI out to work..

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    5

    Troubleshooting trying to get MIDI out to work..

    I want to send Midi data through a 5-pin Din connector with Teensy LC. I attached a 47 ohm resistor 0.25w 5% on both pin 1(TX) and 3.3v. And i have ground connected to the middle DIN pin (have tested it, ground is there) I have double checked the schematic as to which pins on the DIN connector to connect them to and they seem to be accurate, like the pins aren't wrongly attached... I was thinking maybe 5% resistance might be the problem, like its too much? But I wanted to ask to see if someone knew. I tried using the example BASIC_IO from the arduino MIDI library and testing with a midi cable connected to an instrument capable of receiving midi (2 different instruments actually, which i have tested and they can receive midi sent from each other so I know the problem isnt on their side, but with the DIN jack or maybe something else on the Teensy side). I was unsuccessful using the example i also tried the one on the Midi Arduino page, unsuccessful as well.
    Does any 5-pin DIN connector work as a Midi jack or is there a specific kind?

    The code is for a midi bass pedal project (another one). I want the Teensy to be able to send both Midi from the DIN connector and usbMidi. (usbMidi works, have tested, just not the DIN midi):

    HTML Code:
    #include <MIDI.h>
    
    MIDI_CREATE_DEFAULT_INSTANCE();
    
    #define DEBOUNCE 1500
    
    struct key
    {
      int pin;
      int midiKey;
      int debounce;
    
    };
    
    struct key keys[] =
    {
      { 2, 24, 0 },  // C  brown
      { 3, 25, 0 },  // Db red
      { 4, 26, 0 },  // D  red
      { 5, 27, 0 },  // Eb orange
      { 6, 28, 0 },  // E  orange
      { 7, 29, 0 },  // F  yellow
      { 8, 30, 0 },  // Gb green
      { 9, 31, 0 },  // G  green
      { 10, 32, 0 },  // Ab blue
      { 11, 33, 0 },  // A  blue
      { 12, 34, 0 },  // Bb violet
      { 13, 35, 0 },  // B  violet
      { A0, 36, 0 },  // high C  brown
      { 0, 0, 0 }     // end of list marker
    };
    
    const int octaveUp_button_pin = A2;
    const int octaveDown_button_pin = A3;
    const int velpin = A1;
    
    int octave = 0;
    int octave_prev = 0;
    int octaveUp_Button_Voltage = 0;
    int octaveDown_Button_Voltage = 0;
    int last_octaveUp_Button_Voltage = 0;
    int last_octaveDown_Button_Voltage = 0;
    
    
    int time1;
    int time2;
    int interval;
    bool velpin_state = {true};
    bool velpin_prev_state = {true};
    
    int channel = 3;
    
    
    void setup() {
      // put your setup code here, to run once:
      for (int i = 0; keys[i].pin != 0; ++i)
      {
        pinMode(keys[i].pin, INPUT_PULLUP);
      }
      pinMode(octaveUp_button_pin, INPUT_PULLUP);
      pinMode(octaveDown_button_pin, INPUT_PULLUP);
      pinMode(velpin, INPUT_PULLUP);
      MIDI.begin(3);
      Serial.begin(9600);           // set up Serial library at 9600 bps
      Serial.println("Setup complete");
      
      millis();
    }
    
    void noteOn(int midiKey)
    {
      Serial.print("Note On: ");
      Serial.println(midiKey);
    }
    
    void noteOff(int midiKey)
    {
      Serial.print("Note Off: ");
      Serial.println(midiKey);
      MIDI.sendNoteOff(midiKey + octave, 0, channel);
      usbMIDI.sendNoteOff(midiKey + octave, 0, channel);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      //determine octave
      if (octave > octave_prev) {
        //    midiInst.sendControlChange(AllNotesOff, 0,  channel);
        for (int i = 0; keys[i].pin != 0; ++i) {
          noteOff(keys[i].midiKey + octave - 12);
    
    
        } octave_prev = octave;
      } else {
    
        if (octave < octave_prev) {
          //    midiInst.sendControlChange(AllNotesOff, 0,  channel);
          for (int i = 0; keys[i].pin != 0; ++i) {
            noteOff(keys[i].midiKey + octave + 12);
    
          } octave_prev = octave;
        } else {
    
    
          octaveUp_Button_Voltage = digitalRead(octaveUp_button_pin);
    
          // compare the buttonState to its previous state
          if (octaveUp_Button_Voltage != last_octaveUp_Button_Voltage) {
            // if the state has changed, increment the counter
            if (octaveUp_Button_Voltage == LOW) {
              // if the current state is HIGH then the button went from off to on:
    
              if (octave < 24) {
    
    
                octave += 12;
                Serial.println("Octave Up +1 ");
                Serial.print("(Transpose + ");
                Serial.print(octave);
                Serial.println(")");
              }
            } else {
              // if the current state is LOW then the button went from on to off:
    
            }
            // Delay a little bit to avoid bouncing
            delay(50);
          }
          // save the current state as the last state, for next time through the loop
          last_octaveUp_Button_Voltage = octaveUp_Button_Voltage;
    
    
    
    
    
          // read the pushbutton input pin 2:
          octaveDown_Button_Voltage = digitalRead(octaveDown_button_pin);
    
          // compare the buttonState to its previous state
          if (octaveDown_Button_Voltage != last_octaveDown_Button_Voltage) {
            // if the state has changed, increment the counter
            if (octaveDown_Button_Voltage == LOW) {
              // if the current state is HIGH then the button went from off to on:
    
              if (octave > -24) {
    
                octave -= 12;
                Serial.println("Octave Down -1 ");
                Serial.print("Transpose + ");
                Serial.print(octave);
                Serial.println(")");
    
              }
            } else {
              // if the current state is LOW then the button went from on to off:
    
            }
            // Delay a little bit to avoid bouncing
            delay(50);
          }
          // save the current state as the last state, for next time through the loop
          last_octaveDown_Button_Voltage = octaveDown_Button_Voltage;
    
    
    
          int value;
          for (int i = 0; keys[i].pin != 0; ++i)
          {
            value = digitalRead(keys[i].pin);
            if (keys[i].debounce == 0) // Key has been off
            {
              if (value == HIGH)       // Key is now on
              {
                time1 = millis();
                Serial.println(time1);
    
                keys[i].debounce = DEBOUNCE;  // Set the note off debounce counter
    
    
              }
            }
            else                      // Key has been on
            {
              if (value == LOW)      // Key has gone off
              {
                if (--keys[i].debounce == 0) // If Key has remained off for DEBOUNCE scans,
                  noteOff(keys[i].midiKey + octave);
                               
              }
              else                    // Key has not gone off
                keys[i].debounce = DEBOUNCE;  // Reset debounce counter in case we got
              // a small number of key off scans
    
    
    
    
    
              velpin_state = digitalRead(velpin);
    
              if (velpin_state != velpin_prev_state)
              {
    
                if (velpin_state == LOW)
    
                {
                  time2 = millis();
                  Serial.println(time2);
                  interval = time2 - time1;
                  Serial.print("interval: ");
                  Serial.println(interval);
                  velocity = map(interval, 0, 700, 127, 0);
                  if (velocity < 0) {
                    velocity = 0; }
                  Serial.print("Velocity = ");
                  Serial.println(velocity);
                  noteOn(keys[i].midiKey + octave);      // Send the MIDI note on message
                  MIDI.sendNoteOn(keys[i].midiKey + octave, velocity, channel);
                  usbMIDI.sendNoteOn(keys[i].midiKey + octave, velocity, channel);
                }
              }
              velpin_prev_state = velpin_state;
            }
          }
        }
      }
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,815
    I don't know what's wrong, but I can try to quickly answer these 2 questions.

    I was thinking maybe 5% resistance might be the problem, like its too much? But I wanted to ask to see if someone knew.
    5% is perfectly fine.


    Does any 5-pin DIN connector work as a Midi jack or is there a specific kind?
    Any connector which mates properly and reliably connects to the 2 pins needed by MIDI should work.

    Even though you've double checked everything, sharing photos here might help. If we can see how you really connected everything, maybe someone will notice any issue?

    About 1 week ago there was a similar MIDI question. Looking at the photo, it turned out the resistor color wasn't right and it was actually a pair of 47K resistors instead of 47 ohm. Misunderstanding about which 2 pins to use on the DIN connector are a common problem. It's really easy to get them swapped if you look at a diagram for the front side while soldering wires to the back side.

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,176
    Which pin are you using as the MIDI output? The MIDI library defaults to using the Serial1 Tx pin (pin 1). But also, that basic example will only send a midi note if it receives one.
    Try this code which continuously plays a midi note for one second and then off for one second - I know this works.
    Code:
    #include <MIDI.h>
    
    // Simple tutorial on how to receive and send MIDI messages.
    // Here, when receiving any message on channel 4, the Arduino
    // will blink a led and play back a note for 1 second.
    
    MIDI_CREATE_DEFAULT_INSTANCE();
    
    static const unsigned ledPin = 13;      // LED pin on Arduino Uno
    
    void setup()
    {
        pinMode(ledPin, OUTPUT);
        MIDI.begin(4);                      // Launch MIDI and listen to channel 4
    }
    
    void loop()
    {
    //    if (MIDI.read())                    // If we have received a message
    //    {
            digitalWrite(ledPin, HIGH);
            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
            digitalWrite(ledPin, LOW);
            delay(1000);
    //    }
    }
    Pete

  4. #4
    Junior Member
    Join Date
    Nov 2019
    Posts
    5
    I found out they are actually 47kohm...
    So do you think that is the reason it wasn't working?

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,176
    Almost certainly. Change them and see.

    Pete

  6. #6
    Junior Member
    Join Date
    Nov 2019
    Posts
    5
    I now have 47 ohm resistors on both non-ground pins on the midi/din connector. Still not receiving any MIDI data...I tried the code you posted too. I have received usbMIDI from the Teensy just not regular midi from the din connector...another thing I thought is: the 3.3v pin i am using is the one next to pin 23(A9). Could that be the reason?

    Click image for larger version. 

Name:	Photo on 11-23-19 at 4.42 AM #2n.jpg 
Views:	15 
Size:	183.5 KB 
ID:	18248Click image for larger version. 

Name:	Photo on 11-23-19 at 4.43 AM.jpg 
Views:	6 
Size:	158.4 KB 
ID:	18249

  7. #7
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Location
    Florida
    Posts
    425
    Are these pictures reversed from your webcam, based on the resistor photo it looks like it. If so then you have it wired backwards, hereís a photo from sparkfun that may help your orientation:
    Click image for larger version. 

Name:	F7441974-0041-420F-9196-764F66C81AFE.png 
Views:	0 
Size:	597.6 KB 
ID:	18250
    Pin 5 is TX
    Pin 4 is 3.3v
    Pin 2 is shield/ground

  8. #8
    Junior Member
    Join Date
    Nov 2019
    Posts
    5
    sorry that photo made things more confusing. I have tried them both ways...currently have them attached to the pins indicated by the sparkfun photo.

  9. #9
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    164
    @rusty113
    I could be wrong but looking at your first picture it seems your didn't solder the wires to the resistors. If so, how do you expect it to work?

  10. #10
    Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    38
    Something like this is handy in the toolkit.
    Click image for larger version. 

Name:	DSC_0759.jpg 
Views:	1 
Size:	54.7 KB 
ID:	18255

  11. #11
    Junior Member
    Join Date
    Nov 2019
    Posts
    5
    that looks useful. Did you make it?
    I thought that the wires just needed to be making contact for it to work...i didn't solder it yet because i am planning on putting it in a enclosure

  12. #12
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Location
    Florida
    Posts
    425
    That would be especially useful if it had a bi-color LED so it would light up a different color when itís wired backwards, the circuitry is the exact same that you already have built just using a bi-color LED like this:
    Name:  9EADE752-34C1-4EE5-A35A-616985B62659.png
Views: 20
Size:  3.9 KB

  13. #13
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Location
    Florida
    Posts
    425
    As long as your wires have a solid connection you can get away without soldering for prototyping, I typically use alligator clips so I know the connection has some strength to it. If your Teensy is on a breadboard and you have an LED it’s easy enough to connect it straight to the TX pin to verify activity, you could also do a simple loop back test by connecting TX to RX on the Teensy without any other circuitry.

  14. #14
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    164
    Quote Originally Posted by rusty113 View Post
    I thought that the wires just needed to be making contact for it to work...i didn't solder it yet because i am planning on putting it in a enclosure
    Physical contact does not mean electrical contact. There might be some glue residue from the paper tape at the extremities of the resistor legs.

Posting Permissions

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