Matlab and Arduino Serial1 Problem!

Hi everyone, this is my problem:

I'm using Matlab to control my arduino mega 2560 through the MathWorks' Support Package. Everything works just fine, except that i need to send via USB three bytes, and then the arduino should send them via Serial1 (pin 18 on the Mega) to my MIDI keyboard. The problem is that this Serial1 command doesn't seem to be supported by the package! I read that there's a Simulink block that can do this very task somehow, but I need to use a script, not a simulink model.

I thought I could modify the .m file and the .pde file of the package to implement this Serial1.write function, but this is my first programming attempt and I got lost pretty soon.

Please help, how do I say matlab to "Serial1.write"? Any help is important.

Thank you, and sorry for my English.

Hello and welcome :)

If I understand correctly, you send values from Matlab to Arduino, via USB (so it's Serial, not Serial1), and Serial1 links Arduino and the MIDI keyboard.

I think all you have to do in your Arduino program is, send to Serial1 what you receive from Serial

Exemple (simplified):

Serial1.write( Serial.read() );

Thank you for your hint! :)

I modified the "roundTrip" function in the .m file and now it works. The problem now is that this function seems to be able to send only a byte every call. My script is playing a MIDI song, and every note requires 3 bytes. Sending only a byte every serial communication generates a lot of unwanted delays. How can I send 3 bytes together with this function? Writing three serial.write and three serial1.write(..) in the functions doesn't work.

Thanks for your help!

Jevez: Thank you for your hint! :)

I modified the "roundTrip" function in the .m file and now it works. The problem now is that this function seems to be able to send only a byte every call. My script is playing a MIDI song, and every note requires 3 bytes. Sending only a byte every serial communication generates a lot of unwanted delays. How can I send 3 bytes together with this function? Writing three serial.write and three serial1.write(..) in the functions doesn't work.

Thanks for your help!

Where is your code?