Data Acquisition, Inaccurate Data From Arduino To MatLab

조회 수: 4 (최근 30일)
Darryl
Darryl 2013년 3월 14일
I have a light sensor running off an Arduino uno board with a resolution of 0 - 100 and a delay of 1000ms after each sample. I am then using the Serial class within MatLab to extract the data in order to plot a graph.
My main concern is that the data doesn't seem as lively and accurate as what it seems to be within the serial monitor window of the Arduino IDE.
Code:
x = [1:60];
for i = 1:length(x)
y(i) = fscanf(ard, '%d');
end
plot(x,y)
Also, after my loop above has executed, it doesnt feel like 60 seconds of data acquisition has passed, so I added pause(1) method:
x = [1:60];
for i = 1:length(x)
pause(1);
y(i) = fscanf(ard, '%d');
end
plot(x,y)
But this made the data capture much more inaccurate, so my main two questions are:
Is there a more efficient way of capturing sensor data, and when using the function fscanf, does it actually take into consideration the delay(1000) method that the Arduino is outputting, or any size delay in fact?

답변 (1개)

Walter Roberson
Walter Roberson 2013년 3월 15일
fscanf() is going to wait for the line terminator in each case. You should not need the pause() at all.
Could you explain more about "lively and accurate" ?
  댓글 수: 1
Darryl
Darryl 2013년 3월 15일
편집: Darryl 2013년 3월 15일
Thank you for the reply. Sorry, I'll elaborate some more..
Well, when its running through the serial monitor (Arduino IDE), it seems very responsive when moving my hand over the sensor and pointing it at my desktop light, etc.
When I run the fscanf method, there is definitely a long delay, but I wouldn't say 60 seconds. Whilst the method is capturing the data (MatLab prompts busy), and I manipulate the sensor the same way as above, the graph output just doesn't quite seem as it should. For example, I'll get large spikes and flat lining thats either above or below what the serial monitor (Arduino IDE) prints.
I'll attach a picture to demonstrate.

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

카테고리

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