Matlab and arduino Serial communication

1 次查看(过去 30 天)
Hello everyone I am using arduino UNO with Matlab and I want to do a communication between them without using support package. Now the code that I wrote in arduino is:
arduino CODE//-----------------------
int a=1;
int b=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(a);
Serial.println(b);
while (Serial.available()==0)
{}
if (Serial.read()>0)
{
b=Serial.read();}
}
------------------------------- and the Matlab code Matlab code//----------------- clc
clear all
s=serial('COM5','BAUD',9600);
fopen(s);
for m=1:50
z=fscanf(s)
g=z;
fprintf(s,50);
end
fclose(s);
clear all
close all
delete all
--------------------------------
Now I should expect the Command window in matlab to show me
1
0
1
50
1
50
1
50
....
but it get me
1
10
1
10
1
50
1
50
..
and sometimes instead of 10 it gives me -1
WHAT IS ITS PROBLEM?!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by