Borrar filtros
Borrar filtros

matlab serial communication with arduino is very slow

4 visualizaciones (últimos 30 días)
Mahsa Rm
Mahsa Rm el 5 de En. de 2022
Editada: Mahsa Rm el 5 de En. de 2022
I want to send commands with matlab, to arduino uno which is connected to a 4channel relay. but after about 8 seconds of communicating, it takes so long to send commands. so arduino recieves my command late and relay will change state after about 20 seconds delay!
here is my matlab code:
sr = serial('COM4','BaudRate',9600);
fopen(sr); % open Arduino USB port
while 1
command = input('say the command:');
if (command == 0)
break;
end
fprintf(sr,char(command),'async');
end
fclose(sr);
a = instrfind();
fclose(a);
and here is my aruino code(void loop code). and help will be appreciated.
if(Serial.available()>0) // if there is data to read
{
matdata = Serial.read(); // read the data
if (matdata==1)
{digitalWrite(relaypin1,HIGH);
}
else if(matdata==2)
{digitalWrite(relaypin1,LOW);
}
if(matdata==3)
{digitalWrite(relaypin2,HIGH);
}
else if(matdata==4)
{digitalWrite(relaypin2,LOW);
}
if(matdata==5)
{digitalWrite(relaypin3,HIGH);
}
else if(matdata==6)
{digitalWrite(relaypin3,LOW);
}
if(matdata==7)
{digitalWrite(relaypin4,HIGH);
}
else if(matdata==8)
{digitalWrite(relaypin4,LOW);
}
}
else
{Serial.println('None');}

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