- x,y,z components of acceleration are in a 3-vector returned from the readAcceleration routine,
- can return the sample time for each reading in some manner into variable t which is needed for an abscissa plotting location by addpoints
How can I change this code to get the line when plotting the graph? Because I tried adding commands related but still there is no line when I am running the codes
1 view (last 30 days)
Show older comments
WAN NOR NAZIRA MUSTAPA KAMAL
on 2 Feb 2021
Commented: WAN NOR NAZIRA MUSTAPA KAMAL
on 3 Feb 2021
function [] = i2c_sensor()
a = arduino('COM3', 'UNO');
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
for i=1:10
accelReadings(i,:) = readAcceleration(imu);
display(accelReadings(i,:));
pause(1);
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');
end
end
0 Comments
Accepted Answer
dpb
on 2 Feb 2021
You're creating a new animatedline object every time, not adding points to the ones intended...that's not how the examples in the documentation show using it.
function [] = i2c_sensor()
a = arduino('COM3', 'UNO');
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050');
hx_val = animatedline('Color','r');
hy_val = animatedline('Color','g');
hz_val = animatedline('Color','b');
for i=1:10
accelReadings(i,:) = readAcceleration(imu);
t(i)=????
display(accelReadings(i,:));
addpoints(hx_val(t(i),accelReadings(i,1));
addpoints(hy_val(t(i),accelReadings(i,2));
addpoints(hz_val(t(i),accelReadings(i,3));
drawnow
pause(1);
end
end
ASSUMPTIONS:
Read the documentation for both animatedline and addpoints and look at all the examples carefully for further enhancements in using.
3 Comments
Walter Roberson
on 3 Feb 2021
addpoints(hx_val, t(i),accelReadings(i,1));
addpoints(hy_val, t(i),accelReadings(i,2));
addpoints(hz_val, t(i),accelReadings(i,3));
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!