i am try to get the 4 sensors data from a serial port and my data lies in 13,15,17,19 bytes of a packet .I want to plot the data of each sensor in real time but i am facing problem even though one sensor is giving maximum output i couldnt see it i

2 views (last 30 days)
%run('clean');
clear all;
close all;
delete(instrfindall);
s = serial('COM5'); %assigns the object s to serial port
set(s, 'InputBufferSize', 512); %number of bytes in inout buffer
set(s, 'BaudRate', 115200);
%set(s, 'Timeout',10);
%clc;
fopen(s); %opens the serial port
t=1;
disp('Running');
x=0;
y=0;
z=0;
w=0;
while(true)
a1 =fread(s); %reads the data from the serial port and stores it to the matrix a
s1=a1(13);
a=(s1-175)/80;
x =[x a];% Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
plot(x,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
s2=a1(15);
b=(s2-166)/89;
y =[y b];
plot(y,'Color','y');
axis auto;
grid on;
hold on;
drawnow;
s3=a1(17);
c=(s3-168)/87;
z =[z c];
plot(z,'Color','r');
axis auto;
grid on;
hold on;
drawnow;
s4=a1(19);
d=(s4-166)/89;
w =[w d];
plot(w,'Color','b');
axis auto;
grid on;
t=t+1;
drawnow;
%a1=0; %Clear the buffer
end
fclose(s); %close the serial port
  4 Comments
Walter Roberson
Walter Roberson on 12 Mar 2014
which sensor? How do you know it is giving the maximum value?
By the way, my house elves get all of March off to go skiing, so I have to do my own grocery shopping, leaving me out of contact sometimes.

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!