What should I change in this code for me to get in the command window a 10 data of acceleration with 1 data for 1 second?

2 views (last 30 days)
a = arduino();
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
figure;
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050');
x_val = animatedline('Color','r');
y_val = animatedline('Color','g');
z_val = animatedline('Color','b');
stop_time = 10; % time in seconds
count = 1;
tic;
while(toc < stop_time)
data = read(imu);
addpoints(x_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,1));
addpoints(y_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,2));
addpoints(z_val,count:(count+imu.SamplesPerRead-1),data.Acceleration(:,3));
count = count + imu.SamplesPerRead;
pause(0.001);
end
release(imu);

Accepted Answer

Walter Roberson
Walter Roberson on 31 Jan 2021
imu = mpu6050(a,'SampleRate',1,'SamplesPerRead',1,'ReadMode','Latest');
  8 Comments
WAN NOR NAZIRA MUSTAPA KAMAL
I see. But why I observed that the graph is not compatible compare with the data in the table obtained? I meant the value in table is not the same as in the graph

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Mobile Fundamentals 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!