How can I plot bluetooth data in real-time without drawnow?

조회 수: 1 (최근 30일)
Faheem Ershad
Faheem Ershad 2019년 5월 22일
I have an HC-05 module hooked up to an AD8232 Heart rate monitor and an arduino nano. I've looked through the forums and found a few ways to get data over bluetooth into matlab. However, the timing on the x-axis of the figure is highly inaccurate and shows that an ECG waveform occurs every 5 seconds when it should show up about every second. In addition, there is about a 20 second delay for the figure window to show up after hitting run. Any suggestions on how these issues can be avoided?
Here is a screenshot of the output figure:
delayed bt.JPG
Below is my code:
clear all;close all;
tic;
delete(instrfindall)
instrreset;
b = Bluetooth('HC-05',1);
fopen(b);
figure
h = animatedline;
ax = gca;
ax.YGrid = 'on';
startTime = datetime('now');
count=1;
numsamples=2500;
y=zeros(1,numsamples);
while count<length(y)
tic;
a = str2num(fscanf(b));
z(count)=toc;
if length(a)<1
a=0;
else
y(:,count)=a;
end
count=count+1;
t = datetime('now');
addpoints(h,datenum(t),a)
ax.XLim = datenum([t-seconds(15) t]);
datetick('x','keeplimits')
drawnow limitrate
end
toc;
fclose(b);
figure;
plot(linspace(0,seconds(t-startTime),length(y)),y)

답변 (0개)

카테고리

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