Hi,
I want to interface MATLAB with Arduino MEGA.
For the serial reading operation from Arduino MEGA to MATLAB i havn't any problem.
But I don't succeed for the writing operation from MATLAB to Arduino MEGA, this is my code:
Arduino Code:
byte incomingByte = 0;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0)
{
incomingByte = Serial.read();
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
MATLAB code:
function serialMTOA()
s = serial('COM5', 'BaudRate', 9600);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'Parity','none');
fopen(s);
fwrite(s, 5,'uint8','async');
stopasync(s);
fclose(s);
end
Are there some errors?
When I send the Matlab function I see that Arduino receives (TX led blinks) but when I try to see the Arduino Serial Monitor there's nothing.
Others informations: I use the usb alimentation, and only the usb as serial (no others comunication ports).