Serial data lag when transmitted without delay
4 ビュー (過去 30 日間)
古いコメントを表示
Hello Community!
I want to display Serial Data from an Arduino Uno Photodiode Array(16 by 1 Elements). The values are 8 bit. The arduino also turns a stepper motor after each aquisition, so you get some sort of basic computer tomography image.
Problem is, that the data should be displayed in realtime for learning purpose, but if the data is sent by the Arduino (115200 baudrate) without a delay of 5 ms after each 8 bit value, the imagesc() /drawnow() function gets delayed be approximatly 20 sec.
If a delay of 5 ms on the arduino side is added, the drawnow() function feels nearly realtime responsive. But i can't leave that delay in, because the steppermovement would get choppy.
I guess it has to do with the ineffective way of plotting on the Matlab side. Or maybe the standard serial buffer is to small (12 steps per sec*16 values of 8bit(or 1 byte)=192 bytes per second)? Could anybody suggest better practice?
Thank you,
Markus
Code:
A=zeros(16,360); %Defines 16 diodes array with 360 degrees rotation/steps
B=size(A,2);
serialPort = 'COM3'; % defines COM port of Arduino Matlab Command "seriallist" zeigt alle vorhandenen
s = serial(serialPort,'BaudRate',115200)
fopen(s);
pause(2); % Pause of 2 sec is crucial, otherwise connection is not established correctly
figure('Name','Sinogram')
fprintf(s,'%c','a'); %starting command for the image aqusition
try
for y=1:B
for x=1:16
dat = fscanf(s,'%d'); %reads serial data
A(x,y)=dat; %fills Matrix
end
disp(floor(y/B *100)+"% loaded");
drawnow('limitrate')
imagesc(A)
xlabel('Angle - \theta (degree)');
ylabel('Value - x\prime (Pixel)');
end
catch
instrreset;
end
fclose(s);
disp('Data aquiered');
colorbar;
1 件のコメント
Joao Ferreira
2020 年 6 月 12 日
編集済み: Joao Ferreira
2020 年 6 月 12 日
Try adding the function:
flushinput(serialPort);
after the drawnow, so Matlab discards any data buffered..
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Arduino Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!