Connect e-piano with arduino, Issue with midi connection.

Hey everyone,

first of all, sorry for posting here, but somehow I cannot post in the sub “general electronics”. If a mod is seeing this, please feel free to move this topic.

for a bigger project I am currently trying to connect my e-piano (Korg SP 100) to my arduino (Uno) with the help of a self made midi input circuit. I am following this instruction Notes and Volts: Midi for the Arduino - Build a Midi Input Circuit. The code can be found here Notes and Volts: MIDI for the Arduino - Arduino MIDI Library Input Test.
So far I set up the circuit and got the program code running on the Arduino. But somehow when I connect my piano with the circuit and play a note nothing happens. Either way the circuit is wrong or a component is broken. So i want to check every component, starting with the midi output of my piano. Question is, how can I check it if its working? Tried to use a voltmeter, but I read, that the interval of the current is too short to be measured. Another idea was to set up a small circuit with an LED and a 220 ohm resistor to connect the pin 4 and 5 of the midi output and see if I get a light signals that way. I tried and didnt get any, so either the midi is really broken or I used the wrong methods of testing.
Anyone has any ideas, what else I could do or how I could test the midi output of my piano? Buying a usb-midi cable is of course an option, but will take one week to be delivered. So maybe the is a faster solution.

Greetings :slight_smile:

In my opinion those links are not good. You should dig out the wanted information and present it here. The same for the code.
I don't spend time ton archeologic excursions to find things. Time can be used in a better way.

True. Here is a picture of the circuit:


And thats the code, which is used:

#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();

void setup() {
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
  // OMNI sets it to listen to all channels.. MIDI.begin(2) would set it 
  // to respond to notes on channel 2 only.
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function you want to call when a NOTE ON command
  // is received. In this case it's "MyHandleNoteOn".
  MIDI.setHandleNoteOff(MyHandleNoteOff); // This command tells the Midi Library 
  // to call "MyHandleNoteOff" when a NOTE OFF command is received.
}

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

// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,HIGH);  //Turn LED on
}

// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,LOW);  //Turn LED off
}

Though it might not be relevant because it has worked for other people with the same code.

Well done! Perfect!
Check the pin numbers used in that 5 pin DIN connector. One of the connections needs to be earth, ground, to make a circuit. The level produced needs to be higher then some 2 volts to trigger the opto copler.

Check the baud rate settings in the sending device. Does MIDI lib set the baud rate for the receiving code? I see nothing like "Serial.begin(baud_rate)".

Railroader:
One of the connections needs to be earth, ground, to make a circuit. The level produced needs to be higher then some 2 volts to trigger the opto copler.

You should never connect the MIDI input connector to ground/earth. MIDI uses a current loop, not a voltage referenced to ground. MIDI devices should be galvanically isolated to prevent ground loops and many other ground-related issues, that's the whole point of using an opto-coupler in the first place.

Railroader:
Check the baud rate settings in the sending device. Does MIDI lib set the baud rate for the receiving code? I see nothing like "Serial.begin(baud_rate)".

Calling MIDI.begin(...) does that for you.

I suspect a hardware issue. Check the DIN pin numbers, the order depends on which end of the connector you're looking at, and whether you're using male or female jacks.

Pieter

PieterP:
You should never connect the MIDI input connector to ground/earth. MIDI uses a current loop, not a voltage referenced to ground. MIDI devices should be galvanically isolated to prevent ground loops and many other ground-related issues, that's the whole point of using an opto-coupler in the first place.Calling MIDI.begin(...) does that for you.

I suspect a hardware issue. Check the DIN pin numbers, the order depends on which end of the connector you're looking at, and whether you're using male or female jacks.

Pieter

No, no, no connection of grounds. I just wanted You to check, in this case that current + and current - are on pin 4 and 5 in the Din contact. Look into the DIN plug! As I remember You can read pin numbers in them! Light and magnifier... Watch the polarity, 4 and 5, or 5 and 4, if You understand.

Okey. Does the MIDI library set the same baud rate as the sending device?

I double-checked the position of the DIN contacts. However, somehow the problem solved itself magically. I could get the same parts again and build the same circuit and somehow this one was working. Then I replaced the new parts with the old parts and it was still working. So in the end I don't know what the issue was. Yesterday it didn't work to build the circuit three times again but today it works.
Well, thanks for your ideas, I am not that much in electronics yet, but your recommendations are a good way for further readings.

Nice it's working now!
Maybe a loose little flake of metal, or a strain of wire, made a short ciruit somewhere.