code for checking midi in and out

hi people!

i'm new in arduino :slight_smile:
for my pre diploma test on my design university i'm developing a heptatonic keyboard.
to setup the keyboard, to change the tones and the intervals,... i wanna use a arduino uno.
i already programmed the code with the help of a friend who is studying informatics.
now i build the interface with midi out which is already working and a in by trying two different schematics which is not working.
one with a cny17-2 optocopular and one with a 4n28.
both don't work :frowning: :frowning:
the electrics teacher of my university checked both with an oscilloscope. everything looks fine.
to test, that it's not because of my wrong more difficult code, i made an easy code, which is just writing on the serial out what comes into the serial in.
it's like this:

int midisignal;

void setup()
{
Serial.begin(31250);

}

void loop() {

midisignal = Serial.read();
Serial.write(midisignal);
}

but it is still not working.
is this code also wrong for checking my midi in?
are there other/better ways to check my midi in?

thanks a lot for your help :slight_smile:

now i got it :slight_smile:
i forgot the serial available thing
without there were always a lot of "-1"s :slight_smile:

the right code to have a midi in = midi out is

int midisignal;

void setup()
{
Serial.begin(31250);

}

void loop() {

if (Serial.available() > 0) {

midisignal = Serial.read();
Serial.write(midisignal);
}
}