hello,
i want to plot serial port of my sensor(3_axis magnetometer snsor-hmc5883l), by matlab. i can plot it but i have delay in the matlab plotting. how can i fix this problem?
my arduino bautrate is 1152000 and the delay in the loop is delay(13): output of my arduino is like this:
529.92,4.60,-169.28
529.92,4.60,-171.12
529.92,4.60,-170.20
530.84,3.68,-169.28
529.92,4.60,-169.28
529.92,3.68,-170.20
529.92,4.60,-170.20
529.92,3.68,-170.20
529.92,3.68,-170.20
530.84,3.68,-170.20
my matlab code is :
function[] = Plot_Data()
delete(instrfind);
clc
clear all
close all
s=serial('COM3','Baudrate',115200);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'Parity','none');
fopen(s);
xaxis=0; yaxis=0; zaxis=0;
str='';
sen=0;
j=1;
x=0;
h = figure(1);
hlinex = line(nan, nan, 'color', 'red'); %for X
hliney = line(nan, nan, 'color', 'blue'); %For Y
hlinez = line(nan, nan, 'color', 'green'); %For Z
%%delete(instrfind);
while(1)
str=fscanf(s);
sen=str2num(str);
xaxis(j)=sen(1);
yaxis(j)=sen(2);
zaxis(j)=sen(3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xX = get(hlinex, 'XData');
yX = get(hlinex, 'YData');
xX = [xX j];
yX = [yX xaxis(j)];
set(hlinex,'XData',xX, 'YData',yX);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xY = get(hliney, 'XData');
yY = get(hliney, 'YData');
xY = [xY j];
yY = [yY yaxis(j)];
set(hliney,'XData',xY, 'YData',yY);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xZ = get(hlinez, 'XData');
yZ = get(hlinez, 'YData');
xZ = [xZ j];
yZ = [yZ zaxis(j)];
set(hlinez,'XData',xZ, 'YData',yZ);
grid on
legend('X Axis','Y Axis', 'Z Axis');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j=j+1;
pause(0.01); % make sure sample faster than resolution
end
end