Data Acquisition, Inaccurate Data From Arduino To MatLab
4 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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" ?
参考
カテゴリ
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!