Effacer les filtres
Effacer les filtres

Matlab and arduino Serial communication

1 vue (au cours des 30 derniers jours)
bachelor student
bachelor student le 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?!

Réponses (0)

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by