Getting Acceleration Data from MPU-9250 Sensor
6 views (last 30 days)
Show older comments
Hi! I am trying to get acceleration data from an MPU-9250/6500 sensor that is connected to an Arduino. I followed the documentation for mpu9250 and readAcceleration, this is my code.
a = arduino('/dev/cu.usbmodem14201', 'Uno', 'libraries','I2C');
sensorobj = mpu9250(a);
accelReadings = readAcceleration(sensorobj);
But I am getting the following error "Expected sensor not detected. Connect the right sensor to the hardware and try again.". I am using the 2021 version of Matlab but I don't think this should cause any issues with this function.
0 Comments
Answers (1)
Shreshth
on 6 Dec 2023
Hello Ailen,
The error message "Expected sensor not detected" suggests that the MATLAB script is unable to communicate with the MPU-9250/6500 sensor. This could be due to a variety of reasons, such as incorrect wiring, a faulty sensor, an incorrect I2C address, or a problem with the Arduino board or its connection to the computer.
Here are some steps to troubleshoot the issue:
1. Check the Wiring: Ensure that the sensor is correctly wired to the Arduino. The MPU-9250 typically requires connections for VCC, GND, SDA, and SCL. Double-check that these are connected to the correct pins on the Arduino and that there are no loose connections.
2. Verify the I2C Address: The MPU-9250 can have different I2C addresses depending on how the `AD0` pin is wired (it can be either `0x68` or `0x69`). Make sure you know the correct address for your setup. If necessary, you can scan for I2C devices connected to your Arduino to find the correct address.
3. Arduino IDE and I2C Scanner: Use the Arduino IDE to upload an I2C scanner sketch to your Arduino. This will confirm if the Arduino can detect the MPU-9250 sensor and what address it's on. If the scanner does not detect the sensor, there is likely a hardware issue with the sensor or the connections.
4. Check the Arduino Board and Port: Make sure the Arduino board is functioning correctly and that you've selected the correct port in MATLAB (`'/dev/cu.usbmodem14201'` in your case). You can verify the port and board by uploading a simple sketch using the Arduino IDE.
5. Update Libraries and Firmware: Ensure that you have the latest version of the necessary libraries and that the Arduino's firmware is up to date.
6. MATLAB Compatibility: Although you mentioned that you're using MATLAB 2021, which should be compatible with the `mpu9250` function, it's still worth checking to see if there are any known issues or updates for the MATLAB support package for Arduino hardware.
7. Power Supply: Make sure that the sensor is receiving the correct voltage. Some boards work on 3.3V while others are 5V tolerant. Supplying the wrong voltage could damage the sensor or cause it to operate incorrectly.
8. Try a Different Sensor or Arduino: If possible, try using a different MPU-9250 sensor or a different Arduino board to determine if the issue is with the specific sensor or board you're using.
Here is the documentation by Mathworks for furthur clarifications
If you've gone through these troubleshooting steps and the issue persists, you may need to seek further assistance from the support forums for MATLAB or Arduino, as there may be a more specific issue at play with your setup.
Thank You,
Shubham Shreshth
0 Comments
See Also
Categories
Find more on Arduino Hardware 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!