fscanf reads 0 from Arduino (connected to force/ pressure sensor) - despite non 0 values seen in Ardunio serial monitor
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I am trying to read out from a force/ pressure sensor that is connected to an Ardunio Micro (connected by USB) into MATLAB.
When I use the Ardunio software and look in the serial monitor, pressing the force sensor shows values going up and down as they should:
![SerialMon.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224640/SerialMon.png)
However, when I try and read using matlab (using various read/ scan functions) I get 0's (even when pressing as above)
![MAT_0s.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224641/MAT_0s.png)
I tried changing the format of the output I was expecting to %s %s %s %d etc, but this did not work (and I think is not the correct format anyway). I tried various other things commented out below:
delete(instrfindall);
seriallist;
s1 = serial("/dev/tty.usbmodem1421");
s1.BaudRate = 9600; % rate of communication of serial monitor with
% s1.Terminator = 'CR/LF'; % might I need to change the terminator? It is
% default set as 'LF' (line feed?)
fopen(s1);
s1.status;
% Do I need to send it something?
% fprintf(s1, 'XXX');
for l = 1:50
pause(.1)
fscanf(s1)
% no idea what the difference between these types of scan are
% fgetl(s1)
% fread(s1)
% fgets(s1)
% cant work out how to specify the output properly
% fscanf(s1, '%s %s %s %d')
% fscanf(s1, '%s %d')
% fscanf(s1, 'Analog reading = %d')
end
fclose(s1)
delete(s1)
clear s1
clear all
As you can see I am a total novice... Any help would be very very very much appreciated, as I am supposed to have this up and running by Monday :s
Thank you all!
This is my Ardunio code in case helpful
![Ardunio_code.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224642/Ardunio_code.png)
댓글 수: 0
답변 (2개)
Vishnu Vardhan
2019년 6월 15일
Hi Harriet,
I think you haven't tried using the function readVoltage function available in MATLAB. Why don't you give it a try.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File 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!