MIDI Project. Need help.

Let me preface this by saying I suck at coding.

What I want to do is to pass MIDI data through 2 arduino's connected to xbee modules by Xbee shields. I have connected 2 Olimex shields to the arduino's as well.


The olimex shields are powered by the arduino board and the rx of the Arduino board is connected to the tx of the olimex board and vice versa.

The MIDI data will be sent and recieved by the Keyboard on one end and be sent and recieved by a program called anvil studio on the other end

Using the 2 Olimex shields


I am connected to a keyboard synthesizer on one side and a USB midisport on the other

Diagram of setup:

I can get MIDI notes playing on the keyboard by programming one arduino and using a MIDI library so I know the setup works.

I want to let MIDI data just pass through the Arduino's and go to the keyboard on one end or the pc on the other.

So if I play the keyboard the MIDI data will show up on the monitor and if I send MIDI data using anvil studio I want the keyboard to play. I would really, really appreciate any help on this!

#include <MIDI.h>

int type;
byte data1;
byte data2;
byte channel;


void setup()
{

    MIDI.begin(MIDI_CHANNEL_OMNI);          // Launch MIDI and listen to all channels
}

void loop()
{
  
    while(MIDI.read() > 0){
 
    type = MIDI.getType(); //get type of MIDI message
    data1 = MIDI.getData1(); //get data byte 1
    data2 = MIDI.getData2(); //get data byte 2
    channel = MIDI.getChannel(); //get channel MIDI message is on     
      
  Serial.print((byte)type);    // command
  Serial.print((byte)data1);  // note number
  Serial.print((byte)data2);  // velocity
    }
    
}

void turnThruOn();

This is the code I am using in order to send and recieve MIDI messages from
Anvil Studio -> Arduino -> Keyboard synth
and
Keyboard synth ->Arduino -> Anvil Studio

I can recieve the messages just fine but when I send MIDI messages it sends the notes I want it to send but also plays the first note I tell it to play constantly. It doesn't stop even when I stop sending a stream of note on messages
The note is: NoteOn 60 (Middle C).

Any ideas on what could be causing this?

I also figured out why the the Xbee modules weren't sending MIDI messages even though I can see them on the network.
Turns out, according to; Xbee Adapter - wireless Arduino programming
you have to configure the Xbee's to talk at MIDI baud rate(31250) which cannot be done on pcs with a newer version of Windows than xp as you have to alias the baud rate. I only have 7 and vista at my disposal so I'll have to get an xp laptop on Monday.

Would love to hear any input you guys have.

edit: I see what you're trying to do. You're trying to make a wireless MIDI setup, right?

When sending MIDI data out of the serial port you must use serial write not serial print.