MPU 9250 with ESP32

Hello,

I am trying to read data from the MPU 9250, but I have problems with finding the right library. I have tried lots of them, but none of them worked fine. I tried the SparkFun lib, it worked for a couple of seconds, then values were 0. And I didn't even get the mag data. That is my biggest issue! I haven't found any lib which prints the Magnetometer Values.... I really don't know why...

Has anyone a MPU9250 and ESP32 which works fine? If so, which libraries are used, and are there any little changes in them?

Thank you!

Download the datasheet and write your own routines.

Hi,
What codes have you tried?
Can you post a circuit diagram please?

I hope you googled mpu-9250 esp32
If you use this library and its example, what happens?

Have you looked at this tutorial?
http://www.esp32learning.com/code/esp32-and-mpu-9250-sensor-example.php

Thanks.. Tom.. :slight_smile:

First of all, thx for your answer.
My Cricuit is like that (I don't know yet, whether 5V or 3.3V is better)
5V/3.3V (I tried both) --------- VCC
GND ---------------------------GND
21------------------------------SDA
22------------------------------SCL

I tried the Asukiaaa lib, I get something like this:

sensorId: 113
accelX: 0.72
accelY: 4.95
accelZ: -5.20
accelSqrt: 7.22
gyroX: 15.56
gyroY: 18.43
gyroZ: 22.16
Cannot read mag values
at 86157ms

sensorId: 113
accelX: 0.74
accelY: 4.94
accelZ: -5.14
accelSqrt: 7.17
gyroX: 13.55
gyroY: 21.36
gyroZ: 21.73
Cannot read mag values
at 86659ms

So still no mag...

And for the other lib, I get the error message:

Arduino: 1.8.1 (Windows 10), Board: "ESP32 Dev Module, QIO, 80MHz, 4MB (32Mb), 115200, None"

C:\Users\fkhue\Documents\Arduino\libraries\ESP32-Arduino-MPU9250-master\I2Cbus.cpp: In member function 'esp_err_t i2cbus::I2C::readBytes(uint8_t, uint8_t, size_t, uint8_t*, int32_t)':

C:\Users\fkhue\Documents\Arduino\libraries\ESP32-Arduino-MPU9250-master\I2Cbus.cpp:189:40: error: 'I2C_MASTER_LAST_NACK' was not declared in this scope

i2c_master_read(cmd, data, length, I2C_MASTER_LAST_NACK);

^

I hope that helps you :smiley:

Hi,
So the monitor says "Cannot read mag values"?

Have you tried the MPU on a UNO or Nano?
Where did you get your MPU, it could be a cloned/fake.

The fact that the code has tried to get the values seems to me that the code and library are working and it may be a MPU fault.

Tom... :slight_smile:
PS can you please post the code using the Asukiaaa lib?

Hi,

first of all, i don't have an MPU9250, but I do have an ADXL355.
I programmed it on an Arduino UNO, which basically is C++, and I'm using I2C to communicate.
I've made a repository on GitHub, you can find it here.
I only displayed the acceleration data, but it should work the same when reading the addresses of the Mag data.
Maybe you can use some inspiration from this repository.

The problem that I encountered was somewhat the same as yours:

it worked for a couple of seconds, then values were 0

I came to the conclusion that something was wrong with the address, so i used an I2C-Scanner to see which address I was using for the ADXL355. There were two of them:

  • Address 0x53, this address is shown when the SDA pin was pulled HIGH.
  • Address 0x1D, this address is shown when the SDA pin was pulled to GND.

Maybe it has something to do with that? I saw [this](invensense-imu/README.md at main · bolderflight/invensense-imu · GitHub MPU-9250 I2C address,of 0x68 (AD0 grounded).) on the internet:

The MPU-9250 I2C address will be 0x68 if the AD0 pin is grounded or 0x69 if the AD0 pin is pulled high.

One more thing, the device is operating on 3.3V, but the module contains a 3.3V regulator so the module should be supplied with 5V on the VCC pin.

I hope this helps you a little,

kind regards,

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.