How to Plot a graph of Time versus Digital data?
1 view (last 30 days)
Show older comments
I have a Microcontroller board(Arduino Uno) that sends data between 1 - 1024(digits)for every 1000 mili seconds to the COM port 5 of Windows XP PC.
I want to receive this data in to MatLab and display a graph of Time versus Data. I want to display both Static and Dynamic or whichever is possible easily.
Kindly, some one who is reading this, help me to write the code.**
I tried this code shown below, but I don't see anything on the graph.
% Author :Sreeram Mohan
% Tested with arduino Duemilanove
% Open source software for the arduino duemilanove !
% Feel free to use and suggest updates !!!!
clear all;
clc;
s1 = serial('COM5'); %define serial port
s1.BaudRate=9600; %define baud rate
%open serial port
fopen(s1);
clear data;
for i= 1:100 %acquisition of 100 points
data=fscanf(s1);%read sensor
sine_data=str2double(data);
y = 5*sin(2*3.14*2000*sine_data);
subplot(1,2,1)
stem(y,i);
title('Values at each time interval');
xlabel('number of points');
ylabel('Sine Values for each point');
drawnow;
subplot(1,2,2)
hold on;
plot(sine_data,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
title('Sine Wave plotted from data obtained from arduino');
xlabel('number of points');
ylabel('Sine values ');
drawnow;
end
% close the serial port!
fclose(s1);
My question could be stupid. Forgive me for that.
Thank you, Suresh Jonna
0 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware 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!