Need help with plotting accelerometer readings from MPU6050 + Arduino.

15 ビュー (過去 30 日間)
Hannah Sabir
Hannah Sabir 2017 年 12 月 31 日
回答済み: Gayatri Menon 2022 年 1 月 7 日
I've written some code in Arduino to collect accelerometer readings from my MPU6050. I now need to plot live readings on a graph on MATLAB but I don't know where to begin. Can anyone point my in the right direction please, im a total newbie with MATLAB.
Thank you in advance!
  1 件のコメント
WAN NOR NAZIRA MUSTAPA KAMAL
WAN NOR NAZIRA MUSTAPA KAMAL 2021 年 1 月 1 日
Hi. I am Nazira. I want to ask may you share the code in Arduino the one that you mention? Because I also now do a project to monitor real time of an earthquake by using MPU6050 with Arduino and Matlab. Do you mind to help me?

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

回答 (3 件)

magate
magate 2017 年 12 月 31 日
Import tool should be the easiest way to get started. Good luck!
  2 件のコメント
Hannah Sabir
Hannah Sabir 2017 年 12 月 31 日
Hi, Thank you for this, however I want it to be a live reading so i'll need to make a connection..
magate
magate 2017 年 12 月 31 日
That is going to be a little more complicated. You could try this or just opening a serial connection.

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


Mustafa Abu-Mallouh
Mustafa Abu-Mallouh 2018 年 12 月 30 日
Write a loop that updates a dataset with new data pulled from the sensor every iteration. Then, plot the updated dataset on the same figure within the iteration. See example below:
i = 0; % Initialize counter
max_data_len = 360; % Desired dataset length
% Initialize variable size for speed
Angle = zeros(max_data_len,1);
Accel_X = zeros(max_data_len,1);
while i < max_data_len
i = i+1; % Step iteration
Angle(i) = i; % Use counter variable as angle
Accel_X(i) = sind(i); % Store sine of angle
figure(1) % Ensure plotting on same figure
plot(Angle,Accel_X); grid
xlabel('Angle [degrees]')
ylabel('Sine of Angle')
end

Gayatri Menon
Gayatri Menon 2022 年 1 月 7 日
Hi,
For Arduino board, you could use mpu6050() to connect MPU6050 sensor
a = arduino;
imu = mpu6050(a);
xlabel('Count');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050 sensor');
x_val = animatedline('Color','r');
y_val = animatedline('Color','g');
z_val = animatedline('Color','b');
axis tight;
legend('Acceleration in X-axis','Acceleration in Y-axis','Acceleration in Z-axis');
stop_time = 100;
count = 1;
tic;
while(toc <= stop_time)
[accel] = readAcceleration(imu);
addpoints(x_val,count,accel(:,1));
addpoints(y_val,count,accel(:,2));
addpoints(z_val,count,accel(:,3));
count = count + 1;
drawnow limitrate;
end
Hope this helps
Thanks
Gayatri

カテゴリ

Help Center および File ExchangeI2C Devices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by