SENSOR_INIT_ERROR: MPU6050 IMU Sensor for Arduino Mega 2560 in Simulink

조회 수: 47 (최근 30일)
max1904
max1904 2021년 9월 27일
댓글: Utonna Udochi 2024년 11월 18일 16:02
MATLAB 2021a, Simulink 10.3
Hello,
I have a problem with the Simulink block "MPU6050 IMU Sensor" from the Simulink Support Package for Arduino Hardware (version 21.1.2). The Arduino Mega 2560 is connected to the MPU-6050 sensor and the upload of the Simulink model works. However, the value 32 (SENSOR_INIT_ERROR) appears over the status output of the MPU6050 IMU Sensor block, so no measurements are displayed to me.
Do I have to initialize the sensor by myself before? If yes, how does this work?
Many thanks and best regards.
  댓글 수: 1
Arun Kumar
Arun Kumar 2021년 9월 30일
Hi Max,
You don't have to initialize the sensor manually. Sensor initialization is done by the generated code. Sensor init error could be due to wrong sensor id. This block expects the WHO_AM_I register to be 0x48.
Thanks,
Arun

댓글을 달려면 로그인하십시오.

답변 (4개)

Donny WARINT
Donny WARINT 2023년 9월 30일

Nathan Hardenberg
Nathan Hardenberg 2023년 2월 2일
I tried the same thing and got the same problem. I tested with an Arduino Mega and UNO. Both had the same problem! With the MATLAB Hardware Support package (not Simulink) reading out the sensor worked fine.
This leaves me to believe that there is an error with the Simulink-Block for the MPU6050.
Matlab Version: R2022a | Windows 11 | Simulink Support Package for Arduino Hardware: Version 22.1.5
A workaround is buying/using another IMU. I Bought the MPU-9250 and it worked like expected! You just have to choose the MPU9250-Block in Simulink.
  댓글 수: 1
Utonna Udochi
Utonna Udochi 2024년 11월 18일 16:02
I think you only need to switch the SIMULINK block. I read values from my 6050 with the 9250 block.
Matlab Version: R2024b

댓글을 달려면 로그인하십시오.


Ivano Falco
Ivano Falco 2023년 2월 4일
Try to 'Run with IO'
  댓글 수: 1
Nathan Hardenberg
Nathan Hardenberg 2023년 2월 6일
I tried it with IO. But I got the same error result.
I also want to run my model on the Arduino later. Then running in IO would defeat the purpose.

댓글을 달려면 로그인하십시오.


Gayatri Menon
Gayatri Menon 2023년 6월 9일
Hi,
If you have MATLAB support package for Arduino installed, can you try using the below MATLAB IO workflow
>> a = arduino
>> imu = mpu6050(a)
>> imu.readAcceleration
Documentation on MPU6050 - MATLAB
If the above works for the sensor, then you can use MATLAB function block in Simulink to generate code to read data from sensor and run your code in Arduino.
Note : Open the model in Simulink. Double click the MATLAB function block to view the code. Modify the function to read data from MPU6050 instead of MPU9250 (mpu9250(a) -> mpu6050(a)) and remove the code that is not relevant for you before trying build and deployment)
Hope this helps
Thanks
Gayatri
  댓글 수: 1
Thale
Thale 2023년 6월 26일
I tried this for the mpu6050, and with an arduino Uno. sadly it didnt work. How would you do it, if you just want to read angular rate from the imu?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by