フィルターのクリア

Adxl 335 + arduino + matlab

7 ビュー (過去 30 日間)
hanif omar
hanif omar 2020 年 11 月 10 日
編集済み: Eduard Castells 2023 年 3 月 26 日
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 件のコメント
Eduard Castells
Eduard Castells 2023 年 3 月 26 日
編集済み: Eduard Castells 2023 年 3 月 26 日
Line 37, what is VA? I am getting an error

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulation, Tuning, and Visualization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by