フィルターのクリア

Matlab and arduino Serial communication

1 回表示 (過去 30 日間)
bachelor student
bachelor student 2016 年 9 月 19 日
編集済み: bachelor student 2016 年 9 月 19 日
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 Center および File ExchangeMATLAB 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