No data from the magnetometer [MPU9250][AK8963]

Hello everyone, I have a problem with firing the magnetometer in the Gy-91 [MPU9250][AK8963]. The accelerometer and gyro are working and giving correct data. Unfortunately, the magnetometer gives me only 0.

tmagX:0 tmaxY:0 tmagZ:0 thorizontalDirection:0.00
tmagX:0 tmaxY:0 tmagZ:0 thorizontalDirection:0.00
tmagX:0 tmaxY:0 tmagZ:0 thorizontalDirection:0.00
tmagX:0 tmaxY:0 tmagZ:0 thorizontalDirection:0.00
tmagX:0 tmaxY:0 tmagZ:0 thorizontalDirection:0.00

This is my code

#include <MPU9250_asukiaaa.h>
MPU9250_asukiaaa mySensor;
float mDirection;
uint16_t mX, mY, mZ;

void setup() {
  Wire.begin();
  mySensor.setWire(&Wire);
  mySensor.beginMag();
}

void loop() {
  Serial.begin(115200);
  mySensor.magUpdate();
  mX = mySensor.magX();
  mY = mySensor.magY();
  mZ = mySensor.magZ();
  mDirection = mySensor.magHorizDirection();
   Serial.print ("\ tmagX:" + String (mX));

  Serial.print ("\ tmaxY:" + String (mY));
  
  Serial.print ("\ tmagZ:" + String (mZ));
  
  Serial.println ("\ thorizontalDirection:" + String (mDirection));
}

I found a clue here, but I don't know how to apply it to arduino. I am a layman and thank you in advance for your help.

The first step is to run a I2C Scanner sketch.
I assume that it can find the sensor.

You could have a fake sensor, or a real sensor with missing magnetometer, or a fake sensor with a missing magnetometer :crazy_face:
Can you give a link to the library that you use ?
Where did you buy that sensor module ? I assume Amazon / Ebay / Aliexpress ? Then you should buy a normal sensor.

Which Arduino board do you use and can you show a photo of your project ?

1 Like

I use stm32f411 board.

I have 2 gy-91 one from aliexpress second from

I use this library

My photo project:

I2C scanner
I2C Scanner
Scanning...
I2C device found at address 0x76 !
done

Scanning...
I2C device found at address 0x76 !
done

Thanks for the photo and links.

The MPU-9250 has an ID at register 0x75 and the library has a special function to read from register 0x75.

byte id;
mySensor.readId( &id);
Serial.println( id, HEX);

Have you seen this issue: Magnetometer reading error · Issue #22 · asukiaaa/MPU9250_asukiaaa · GitHub

The library might not work with the magnetometer.
I think you have to try an other library.

Perhaps you should also look for a better sensor. The MPU-6050 and MPU-9250 have too many odd things. The manufacturer has made versions that are different for some clients, there are also fake versions.

[ADDED]
I'm not happy with that module. It has a voltage level converter with 2k2 pullup resistors. That is the wrong value, pullup resistors of 10k would be better.
Have you powered the 3.3V to the 3V3 of the sensor module and the VIN of the sensor module is not connected ? I think that the level shifters don't work. You could also connect 3.3V to VIN.
The best option is to not use the 3.3V, but only 5V to VIN and don't connect something to the 3V3 pin of the sensor module. I know that is weird, but as I wrote: I'm not happy with that module

[EDIT] not 5V to VIN

1 Like

Ok i connect VIN to 5V and serial monitor write this but the values don't change all the time they are constant, despite moving the sensor:

tmagX:0 tmaxY:10090 tmagZ:32258 thorizontalDirection:-68.20
tmagX:0 tmaxY:10090 tmagZ:32258 thorizontalDirection:-68.20
tmagX:0 tmaxY:10090 tmagZ:32258 thorizontalDirection:-68.20

I Will try to find another library

I also dislike this sensor. The only reason I use it is because of the included bmp280.

I also don't see the magnetometer using i2c scanner on 30 differents units from different sources. The scan do see it from time to time but it never get to make it actually work.

I can confirm that except the magnetometer, everything work fine if you power the sensor with either 3.3 or 5 volts but the power need to be applied on the vin pin. Never on the 3.3v pin. The vin power also determine the u2c signal level. I powered them with 3.3v so I have a 3.3v IIC level.

You can also wired the vin pin to the i2c addr pin to change the bmp280 IIC address. Handy.

But I wish I have chosen a different unit when I first start my design.

1 Like

Oops :blush: I was wrong, cdb101 is correct.
If the 5V is connected to VIN, then the level shifters shift up to 5V. That is not okay.
Power the VIN with 3.3V.

The STM32F411 "BlackPill" is a 3.3V board. Connect the 3.3V to VIN.

1 Like

does not work alone 0 further ...

I try install lib from link @ Koepel

But I get this message. And I don't know where to get the eigen.h, I can't find it.

C:\Users\backu\OneDrive\Dokumenty\Arduino\sketch_dec26a\mpu9250.h:38:10: fatal error: eigen.h: No such file or directory
   38 | #include "eigen.h"  // NOLINT
      |          ^~~~~~~~~
compilation terminated.
exit status 1

It seems to me that the ethos will work on Stm32F4, although it says that this is the only lib that works correctly with GY-91

Colleagues, tell me what sensor to buy so that I could, as a layman, simply use a magnetometer with tilt compensation to determine the direction ??
I give up with that GY-91

On discord I received this information, but it tells me nothing at all.

this indicates the address should be 0x68 or 0x69 MPU-9250 Hookup Guide - SparkFun Learn, 0x76 is usually a temp or baro sensor SDA and SCL should have external pull-up resistors (to 3.3V).

If you want something that works, then buy good boards and good modules from good sellers. The Arduino boards are good quality. The good sellers are Adafruit, Sparkfun, Pololu and more. In most countries there are local seller that sell their parts. Sometimes they have to order things and that might take a few weeks.

Adafruit has the best tutorials. So if you buy a sensor from Adafruit and follow their tutorial, then it will work, and you probably don't even have to ask for our help :sunglasses:

You could also buy an official Arduino board. I prefer the SAMD21G processor, which is on the Arduino Zero and most MKR boards :relaxed:

If you buy fake or counterfeit cheap rubbish from AliExpress / Amazon / Ebay with wrong designed modules, with the wrong circuit and wrong components, then it is very obvious that you are in for a lot of trouble. You get what you asked for :rage:
Or should I say: welcome to planet earth :earth_africa:

A good option is the LSM sensors :smiley:
Calibrate the sensor, and maybe use AHRS.

There is a good chance that your MPU-9250 is real and has a magnetometer, but I'm a little lost now. To check the sensor, I would like to know its ID.

Well this is because the your board (that we can see in one of your post) not only come with the mpu9250 but also with a bmp280 sensor. The BMP measure pressure and temperature and have IIC address 0x76. The mpu9250 have the IIC address 0x68. The magnetometer is in fact a third IIC sensor on this board. It also have is own IIC address but is accessed through the mpu9250 address. This is why it give trouble I think. Libraries only access the data indirectly.

If you connect Vin to the address pin on the board, the IIC address will change to 0x69 ( the mpu) and 0x77 ( the bmp280).

1 Like

I think the magic of Christmas worked... xDD

@cdb101 sorry but i'm a bit of a layman in these matters. I know c # and python and I understand the syntax of arduino ... but what does it mean to connect vin to i2c to some sda ​​or scl pin ?? perhaps it is obvious to you, but I am lost .... on my board i2c these are the pins PB6 and PB7. Does it require resistors between sda and scl a vin ??
Thx for answer and thank you in advance for your help...

To make it work you need 4 wires. You can forget about the address change. This is a feature you don't need if using the board alone.
Your 3.3v supply need to be connected to the vIn pin on the mpu board. This is the first pin on the left.
You need to connect the ground to the gnd pin on the mpu board. Third pin from the left.
You need to connect your SDA and SCL wires. Fourth and fifth pin from the left.
** I assume your board is the pink board with a orange square capacitor on it as seen in the picture you sent. You can also include the bmp280 library in your code and then you will have access to pressure and temperature if relevant for you.

Good luck

@ cdb101 this is how I have it connected now, but I still do not have access to the magnetometer on either one or the other GY-91.
When I connect 5V, I have a reading, but always the same

tmagX:0 tmaxY:10090 tmagZ:6453 w kierunku poziomym:-21,80

I am trying to use this library now thejmart but I get an error like this:

GY_91_Example_Code:56:27: error: 'MPU9250_ADDRESS' was not declared in this scope; did you mean 'MPU9250_ADDRESS_AD1'?
   56 |   byte c = myIMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
      |                           ^~~~~~~~~~~~~~~
      |                           MPU9250_ADDRESS_AD1
C:\Users\backu\Downloads\GY_91--master(1)\GY_91--master\GY_91_Example_Code\GY_91_Example_Code.ino: In function 'void loop()':
GY_91_Example_Code:169:22: error: 'MPU9250_ADDRESS' was not declared in this scope; did you mean 'MPU9250_ADDRESS_AD1'?
  169 |   if (myIMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01)
      |                      ^~~~~~~~~~~~~~~
      |                      MPU9250_ADDRESS_AD1
exit status 1
'MPU9250_ADDRESS' was not declared in this scope; did you mean 'MPU9250_ADDRESS_AD1'?

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