필터 지우기
필터 지우기

matlab serial communication with arduino is very slow

조회 수: 4 (최근 30일)
Mahsa Rm
Mahsa Rm 2022년 1월 5일
편집: Mahsa Rm 2022년 1월 5일
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');}

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB 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