¡Hi friends!
It is the first time I try to comunicate Arduino with Matlab. I’ve read that there is a hardware support for arduino devices, but I want to comunicate them via a COM port.
My final objetive is to create a serial monitor (in order to analize and operate with the data MatLab receives from arduino), very similar to the Arduino’s serial monitor. The first step I tried is only to send bytes every second from Arduino and receive it with matlab to print it, but I did not succes.
I am using MatLab 2014a and an Arduino UNO (The SMD ONE :3)
The code I uploaded to my Arduino creates a byte variable with 20 as initial value, then it sends it to via serial port, increment it, sends it again, and so on. Here is the code:
void setup() {
Serial.begin(9600);
}
void loop() {
static byte B = 20;
Serial.write(B);
delay(1000);
B++;
}
In the other hand, in Matlab I am using this: (The thing I tried to do is that MatLab displays the bytes Arduino sends, just as the Arduino’s serial monitos does):
%Creates and configure a serial object and opens the port
P = serial ( comPort );
set( P , 'DataBits' , 8 );
set( P , 'StopBits' , 1);
set( P , 'BaudRate' , 9600);
set( P, 'Parity' , 'none');
fopen(P);
%Read the byte and display it
fread(P)
I expected to receive a number instantly, but after I enter the comand MatLab pauses by a short time and then displays some numbers (instead of just one) and sends a warning 'Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period." (I atacht a picture so as to you understand the problem)
I would be very grateful for your help, I am sure that it is not as simple as writing ‘fread( “serial object” )’, but I don’t know the correct way to do it, particularly to say to MarLab when stops reading.