Borrar filtros
Borrar filtros

Matlab and arduino Serial communication

1 visualización (últimos 30 días)
bachelor student
bachelor student el 19 de Sept. de 2016
Editada: bachelor student el 19 de Sept. de 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?!

Respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by