Hello! I m quite new in App Designer so I m gonna ask for your help. I need to open a serial communication with my Arduino. I have some erros though and I cannot understand why:
delete(instrfind)
arduinoo =arduino('COM6');
arduinoo=serial('COM6');
set(arduinoo, 'BaudRate', 115200);
arduinoo.Terminator = 'CR';
y=zeros(1);
s11=zeros(1);
s12=zeros(1);
s13=zeros(1);
s14=zeros(1);
i=1;
l2=0;
arduinoo.BytesAvailableFcnCount = 40;
arduinoo.BytesAvailableFcnMode = 'byte';
arduinoo.BytesAvailableFcn = @instrcallback;
fopen(arduinoo);
if isvalid(arduinoo)
tstart=now();
while 1<2
data=fscanf(arduinoo);
if real(str2double(data))< 5 & real(str2double(data)) >1.75
l2 = (now()-tstart)*24*60*60;
for j=1:1000
data=fscanf(arduinoo);
y(i+j)=real(str2ouble(data));
app.sa = 'DA';
end
break;
end
fclose(arduinoo);
delete(instrfind);
end
Here is my error:
Error using serial/fscanf (line 153)
Unsuccessful read: Instrument object OBJ is an invalid
object..
data=fscanf(arduinoo);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 309)
Error while evaluating Button PrivateButtonPushedFcn.
Thank you in advance for any help!

 채택된 답변

Harsha Priya Daggubati
Harsha Priya Daggubati 2020년 5월 15일

0 개 추천

Hi,
I guess the issue is with arduinoo object you are creating, which I can infer is invalid. Can you try deleting and clearing the object from the workspace/memory and re-run your code.
You can refer the following documentation links for more help.
Hope this helps!

댓글 수: 5

Criss2112
Criss2112 2020년 5월 15일
thank you so much for your time!
Still couldn't figure it out. I ve tried this way but I get the same error..
Harsha Priya Daggubati
Harsha Priya Daggubati 2020년 5월 19일
Hi,
Is the issue resolved? I can only guess the issue is with 'arduinoo' object. Try doing as mentioned in the link:
One thing to add, it is suggested to use 'serialport' instead of 'serial'. Refer to the documentation for more details.
Criss2112
Criss2112 2020년 5월 19일
Not yet, I read the serial simple in an Matlab script, registred the data into some files and then I used them in App Designer.
I had the same issues after doing this
I ll try also with serialport
Thank you!
Harsha Priya Daggubati
Harsha Priya Daggubati 2020년 5월 20일
편집: Harsha Priya Daggubati 2020년 5월 20일
Also, make sure that the port number to which arduino is connected is same as that mentioned in your script, and baud rate is the same.
Have a look at this published File Exchange submission:
Criss2112
Criss2112 2020년 5월 20일
Yes, it s the same. Com6 and 115200 the baudrate.It works perfectly fine in matlab script when running

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

태그

질문:

2020년 5월 12일

댓글:

2020년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by