Nano not receiving MIDI messages

Hi, so I am currently creating a MIDI to CV module and am still having trouble with my MIDI input circuit. I am following this circuit as my guideline and am sending MIDI messages via MIDI interface with the use of this cable. I am also using this software called MIDIKeys as a virtual keyboard for the MIDI notes. Unfortunately, every time I play a note on the keyboard the Arduino doesn't respond with the blink of the LED. I could really use some guidance on fixing this problem.

Below is also the code that I'm using:

#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();
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.
  MIDI.turnThruOff();
  MIDI.setHandleNoteOn(MyHandleNoteOn); 
  MIDI.setHandleNoteOff(MyHandleNoteOff); 
  Serial.begin(31250);
}

void loop() { // Main loop
  MIDI.read(); // Continuously check if Midi data has been received.
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,HIGH);  //Turn LED on
}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,LOW);  //Turn LED off
}

how can you check if it reverse polarity or a signal at all comes on optocoupler?

I don't know about the cable, i tend to start out with something that i know can transmit (like a midi keyboard) or know for sure can receive (like my soundcard with 1x1 midi port)

MIDI_CREATE_DEFAULT_INSTANCE();

so this means you should connect to hwSerial, on the nano that is pins 0 & 1.

Serial.begin(31250);

there is no need for this, it is included in

MIDI.begin(MIDI_CHANNEL_OMNI);

the problem with this is

  MIDI.setHandleNoteOn(MyHandleNoteOn); 
  MIDI.setHandleNoteOff(MyHandleNoteOff);

that in many cases, a 'notyeOff' commands is transmitted as a 'noteOn' with velocity '0'
It can't be the issue here (yet) since that would mean that the LED would be continually 'on' , but keep it in mind.

well it is 'safe' to swap the pins on the input side of the opto-coupler and check the result.
Which is pin 4 and which is pin 5 on a din plug can be a bit of guess work, are you looking at the plug from the front or the rear and is it male or female etc...
You can test the polarity with a simple test 'snippet'

pinMode(RX_PIN, INPUT);
delay(500);
while (digitalRead(RX_PIN);
digitalWrite(LED,HIGH);

should do the trick, if the pin goes LOW when you send something, the LED should come on.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.