Filter löschen
Filter löschen

Matlab and arduino Serial communication

1 Ansicht (letzte 30 Tage)
bachelor student
bachelor student am 19 Sep. 2016
Bearbeitet: bachelor student am 19 Sep. 2016
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?!

Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by