필터 지우기
필터 지우기

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 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