Adxl 335 + arduino + matlab
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
1 Kommentar
Eduard Castells
am 26 Mär. 2023
Bearbeitet: Eduard Castells
am 26 Mär. 2023
Line 37, what is VA? I am getting an error
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulation, Tuning, and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!