Adxl 335 + arduino + matlab

7 次查看(过去 30 天)
hanif omar
hanif omar 2020-11-10
I am working on a project of connecting an ADXL335 Accelerometer to an Arduino UNO then reading the data in Matlab. So far whenever a reading matlab only show data X-axis.? i hope someone can help
Here is my code :
clear
clc
serialPort = "COM4";
a=arduino();
plotTitle = 'Position AXDL'; % plot title
xLabel = 'Time (s)'; % x-axis label
yLabel = 'Angle (C)'; % y-axis label
legend1 = 'X-Angle';
legend2 = 'Y-Angle';
legend3 = 'Z-angle';
yMax = 180; %y Maximum Value
yMin = -180; %y minimum Value
plotGrid = 'off'; % 'off' to turn off grid
min = -30; % set y-min
max = 30; % set y-max
delay = .01;
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
plotGraph = plot(time,data,'-r' ); % every AnalogRead needs to be on its own Plotgraph
hold on %hold on makes sure all of the channels are plotted
plotGraph1 = plot(time,data1,'-b');
plotGraph2 = plot(time, data2,'-g' );
title(plotTitle,'FontSize',15);
xlabel(xLabel,'FontSize',15);
ylabel(yLabel,'FontSize',15);
legend(legend1,legend2,legend3)
axis([yMin yMax min max]);
grid(plotGrid);
tic
while (toc<50) %Loop when Plot is Active will run until plot is closed
vx=readVoltage(a,'A0');
vy=readVoltage(a,'A1');
vz=readVoltage(a,'A2');
[angleX,angleY,angleZ]=VA(vx,vy,vz);
count = count + 1;
time(count) = toc;
data(count) = angleX(1);
data1(count) = angleY(1);
data2(count) = angleZ(1);
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
set(plotGraph,'XData',time,'YData',data);
%set(plotGraph1,'XData',time,'YData',data1);
%set(plotGraph2,'XData',time,'YData',data2);
axis([0 time(count) min max]);
%Update the graph
pause(delay);
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by