Coder Social home page Coder Social logo

wollewald / mpu9250_we Goto Github PK

View Code? Open in Web Editor NEW
54.0 4.0 25.0 780 KB

An Arduino library for the 9-axis accelerometer, gyroscope and magnetometer MPU9250 and MPU6500. It contains many example sketches make it easy to use.

Home Page: https://wolles-elektronikkiste.de/en/mpu9250-9-axis-sensor-module-part-1

License: MIT License

C++ 98.50% C 1.50%
mpu9250 arduino-library easy-to-use accelerometer gyroscope magnetometer fifo mpu6500 arduino spi i2c

mpu9250_we's Introduction

MPU9250_WE

An Arduino library for the 9-axis accelerometer, gyroscope and magnetometer MPU9250 and the MPU6500. In essence the MPU6500 is a MPU9250 without the magnetometer.

The library contains many example sketches with lots of comments to make it easy to use. I have written them for the MPU9250 / I2C. You can "translate" them easily for the MPU6500. MPU6500_all_data.ino shows how to do this. The use of SPI is shown in MPU9250_SPI_all_data.ino and MPU6500_SPI_all_data.ino.

For further information visit my blog:

https://wolles-elektronikkiste.de/mpu9250-9-achsen-sensormodul-teil-1 (German)

https://wolles-elektronikkiste.de/en/mpu9250-9-axis-sensor-module-part-1 (English)

If you find bugs please inform me. If you like the library it would be great if you could give it a star.

If you are not familiar with the MPU9250 I recommend to work through the example sketches in the following order:

  1. MPU9250_acceleration_data.ino
  2. MPU9250_gyroscope_data.ino
  3. MPU9250_calibration.ino
  4. MPU9250_reusing_autocalib_data.ino
  5. MPU9250_magnetometer_data.ino
  6. MPU9250_all_data.ino
  7. MPU9250_angles_and_orientation.ino
  8. MPU9250_pitch_and_roll.ino
  9. MPU9250_data_ready_interrupt_and_cycle.ino
  10. MPU9250_wake_on_motion_interrupt.ino
  11. MPU9250_FIFO_stop_when_full.ino
  12. MPU9250_FIFO_continuous.ino
  13. MPU6500_all_data.ino

The sketch MPU9250_blank_all_settings.ino can be used as a basis for your own sketches. It contains all setting options.

If the MPU9250 / MPU6500 does not respond

There are various modules with different MPUxxxx ICs out there. Sometimes it's not clearly defined in online-shops what you will really get if you buy an MPU9250/MPU6500 module. It might be an MPU9250, it might be an MPU6500 or it might be something else, although the modules look the same. An indication is the label on the MPUxxxx IC:

MPU9250

The labels I am aware of are:

  • MP92: MPU9250
  • MP65: MPU6500
  • MP651: MPU6515

You can also run the example sketch MPU9250_who_am_I.ino to find out which device you have.

I am using the "Who I am" registers of the MPU9250, MPU6500 and the magnetometer AK8963 to check if the modules are connected. If you create an MPU9250 object, but, for example, you are actually using an MPU6500, the init functions will return "false". However, the gyroscope and the accelerometer will work, because all related registers are the same. For other variants it might be similar. If the library works although you are using a different MPUxxxx, then just be happy, but you will have to live with the init function returning "false" - or find an alternative library.

mpu9250_we's People

Contributors

johanneswilde avatar wollewald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mpu9250_we's Issues

MPU9250 object error: "Does not name a type".

I'm using the library as the examples code, but I'm having problems with the created object for the sensor. An error "Does not name a type" persists even when I alredy put all the available archives .cpp and .h in the project folder. The firsts code lines are exactly same as the examples.

Compilation issue

Hi, I am new to the Arduino Uno, observed following compilation issues. I tried to change some of the header files to c notation, but it is never ending. There may be an easy way out. Could you help me in fixing this compilation error?
C:\Users\ramgk\OneDrive\Documents\Arduino\libraries\Bolder_Flight_Systems_Eigen\src/Eigen/Core:50:10: fatal error: complex: No such file or directory
#include
^~~~~~~~~
compilation terminated.

setSampleRateDivider doesn't work

Hello, first of all: great work with the library, i really appreachiate it! I searched for quite a time for a suitable MPU9250 library that supports the FIFO and SPI. The bolderflight library dropped their FIFO support a while ago.

But I still need a little help, i'm sure it is just a small error on my side.
I want to use the library with the ESP32 multitasking to get a continuous 500Hz reading. For that I want to utilize the FIFO to get 50 Acc Value Triplet's every 100ms. That way it wouldn't influence the measurement when the reader call is 10ms late.

Im using an ESP32 Devkit C with PlatformIO Core 6.1.4 Home 3.4.3, and your library on Version 1.2.6. The Sensor I use is an MPU9250.

I used the following to Sketch to test the functionality, but it seems that the SampleRateDivider doesn't get set properly.
If i lower the delay between the calls to 10ms I also get a reduced FIFO count, but it seems to still sample at more than 6 kHz.

#include <Arduino.h>
#include <SPI.h>
#include <MPU9250_WE.h>

SPIClass SPI_MPU(HSPI);
const int CS_MPU_1 = 26;

MPU9250_WE myMPU9250 = MPU9250_WE(&SPI_MPU, CS_MPU_1, 1);
uint8_t dataSets = 0;

float_t ax_mean = 0;
float_t ay_mean = 0;
float_t az_mean = 0;

uint32_t t_next_exec = 0;

void setup()
{
    Serial.begin(115200);
    while (!myMPU9250.init())
    {
        Serial.println("MPU9250 does not respond");
        delay(1000);
    }
    myMPU9250.setAccRange(MPU9250_ACC_RANGE_2G);
    myMPU9250.enableAccDLPF(true);
    myMPU9250.setAccDLPF(MPU9250_DLPF_1);
    myMPU9250.setFifoMode(MPU9250_STOP_WHEN_FULL);
    myMPU9250.setSampleRateDivider(99);     // this setting doesn't change anything

    myMPU9250.setSPIClockSpeed(4000000);
    myMPU9250.enableFifo(true);
    delay(100);
    myMPU9250.startFifo(MPU9250_FIFO_ACC);
}

void loop()
{
    myMPU9250.stopFifo();
    dataSets = myMPU9250.getNumberOfFifoDataSets();
    for (int i = 0; i < dataSets; i++)
    {
        xyzFloat gValue = myMPU9250.getGValuesFromFifo();
        ax_mean += gValue.x / dataSets;
        ay_mean += gValue.y / dataSets;
        az_mean += gValue.z / dataSets;
    }
    myMPU9250.resetFifo();
    myMPU9250.startFifo(MPU9250_FIFO_ACC);

    Serial.print(millis());
    Serial.print("   ");
    Serial.print(9.81 * ax_mean, 3);
    Serial.print("   ");
    Serial.print(9.81 * ay_mean, 3);
    Serial.print("   ");
    Serial.print(9.81 * az_mean, 3);
    Serial.print("   ");
    Serial.println(dataSets);         // prints 85 even at SRD set to 99 and delay of 20ms

    ax_mean = 0;
    ay_mean = 0;
    az_mean = 0;

    while (millis() < t_next_exec){}
    t_next_exec += 20;              // if lowered to 10, dataSets goes down to 61/62 ( -> samplerate >6kHz)
}

The Serial output shows the following:

09:53:22.205 > 3323 -0.286 -0.130 -10.059 85
09:53:22.223 > 3343 -0.280 -0.115 -10.035 85
09:53:22.243 > 3363 -0.301 -0.115 -10.035 85
09:53:22.263 > 3383 -0.280 -0.114 -10.029 85
09:53:22.283 > 3403 -0.312 -0.120 -10.044 85
09:53:22.303 > 3423 -0.295 -0.126 -10.023 85
09:53:22.323 > 3443 -0.305 -0.133 -10.052 85
09:53:22.343 > 3463 -0.297 -0.130 -10.039 85
09:53:22.363 > 3483 -0.296 -0.115 -10.026 85
09:53:22.383 > 3503 -0.307 -0.134 -10.051 85
09:53:22.403 > 3523 -0.293 -0.112 -10.013 85
09:53:22.423 > 3543 -0.290 -0.128 -10.044 85

Is this library support multiple MPU6500 using SPI?

First of all thanks to the author.

I would like to know is this lib support multiple MPU6500 using SPI?
I have an ESP32 board and more than 6 MPU6500 sensors. I try to connect them together and transfer datas by SPI.
However, it seems that only one sensor connected successfully each time, while other sensor show 'not response' and they return wrong datas.

Does this library make use of the DMP?

i have several MPU6500 and i want to get the Yaw value as well, as i see your library only gives pitch and roll and due to the missing magnetometer yaw is dificoult to get (or so i understand).

i am following a video that is about the MPU6050 and they specify i need a library that reads directly from the DMP. hence my question.

Conversion error in FIFO readout

There is a bug in the readMPU9250xyzValFromFifo function. a the conversion from uin16_t to float does not work with negative values.
this code is working:

Vec3f MPU9250_WE::readMPU9250xyzValFromFifo(){
    uint8_t MSByte = 0, LSByte = 0;
    xyzFloat xyzResult = {0.0, 0.0, 0.0};
    MSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    LSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    xyzResult.x = ((int16_t) ((MSByte<<8) + LSByte) * 1.0);
    MSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    LSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    xyzResult.y = ((int16_t) ((MSByte<<8) + LSByte) * 1.0);
    MSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    LSByte = readMPU9250Register8(MPU9250_FIFO_R_W);
    xyzResult.z = ((int16_t) ((MSByte<<8) + LSByte) * 1.0);
    return xyzResult; 
}

i also recommend reading 6 bytes in one go and then convert. this will be much faster

roughly like this:

uint8_t data[12];
read_bytes(MPU9250_FIFO_R_W, data, 12);
uint8_t index = 0;
a_sen_raw.x = ((int16_t) (data[index+0] << 8) | data[index+1]) * 1.0;
a_sen_raw.y = ((int16_t) (data[index+2] << 8) | data[index+3]) * 1.0;
a_sen_raw.z = ((int16_t) (data[index+4] << 8) | data[index+5]) * 1.0;
index += 6;
g_sen_raw.x = ((int16_t) (data[index+0] << 8) | data[index+1]) * 1.0;
g_sen_raw.y = ((int16_t) (data[index+2] << 8) | data[index+3]) * 1.0;
g_sen_raw.z = ((int16_t) (data[index+4] << 8) | data[index+5]) * 1.0;

Magnetometer not working, and ho to get yaw?

Hello, sorry for maybe asking a stupid question. but i hope someone can help me. I don't know why but my magnetometer value never change it stay on zero all the time. the other function like acce, gyro, roll, pitch works just fine. is the magnetometer not working because the module? i have tried the example only too with no change from myself, but it still the same. also the second question is, how to get yaw value?

Feature: tilt adjusted compass output

Thank you for this great library. It is the only one I have found for the mpu9250 that outputs pitch and roll correctly with my sensor.

I see you have magnetometer x,y,z output. I was wondering if a function can be added to output a tilt adjusted compass heading from these values?

Thanks

Sequence of execution of functions in setup arduino sketch

Hi Wolfgang Ewald,

In the setup function call of [MPU9250_acceleration_data.ino] sketch, there is a comment before the setSampleRateDivider function to call this function only if the DLPF filter is enabled. But, the DLPF enable function call is made later. What is the sequence to follow? I altered the function calls, but do not see any difference in output values.

Error when uploading in xiao esp32s3

c:\Users\user\Arduino\libraries\MPU9250_WE\src/MPU6500_WE.h:337:28: error: section attribute not allowed for 'accOffsetVal'
337 | RTC_DATA_ATTR xyzFloat accOffsetVal; // to be able to keep offsets after deep sleep
| ^~~~~~~~~~~~
c:\Users\user\Arduino\libraries\MPU9250_WE\src/MPU6500_WE.h:338:28: error: section attribute not allowed for 'gyrOffsetVal'
338 | RTC_DATA_ATTR xyzFloat gyrOffsetVal;
| ^~~~~~~~~~~~

getting values from fifo takes long

Hello, thank you for developing this library. I've been searching extensively online, and your library is the only one I've been able to get working with the esp32c3.

Unfortunately, this specific part of the code, which you can see here:
image
takes approximately 1 millisecond for both calls to finish. As a result, when I need to collect 40 samples it adds up to about 40 milliseconds.
Is there any way to optimize these calls for faster execution? Your assistance would be greatly appreciated!

Offset function - no sensitivity

Hi Wolfgang Ewald,

I am using the sketch MPU9250_acceleration_data.ino to get the acceleration data. in which there is a function call myMPU9250.autoOffsets(), which is meant to use it for the calibration based on the comments in the code. When I used this sketch as-is, I do not see any change in output values despite the movement in the MPU9250 using my hand. But, when commented the autoOffsets function call, output values are getting changed with the MPU9250 unit movement with the hand. However, with this comment, the values are not constant, keep changing without any movement as well. I am pasting the sample snapshot values after commenting the autoOffsets function call.
Raw acceleration values (x,y,z):
1280.00 -16127.00 24577.00
Corrected ('calibrated') acceleration values (x,y,z):
1280.00 -16127.00 24577.00
g values (x,y,z):
0.08 -0.98 1.50
Resultant g: 1.80

I am also pasting the code below for the autoOffsets function call, if you can throw some light on this code function, that may help me to understand and use it.

_void MPU6500_WE::autoOffsets(){
enableGyrDLPF();
setGyrDLPF(MPU9250_DLPF_6); // lowest noise
setGyrRange(MPU9250_GYRO_RANGE_250); // highest resolution
setAccRange(MPU9250_ACC_RANGE_2G);
enableAccDLPF(true);
setAccDLPF(MPU9250_DLPF_6);
delay(100);

xyzFloat accelerationOffsetAccumulator{0.f, 0.f, 0.f};
xyzFloat gyroOffsetAccumulator{0.f, 0.f, 0.f};
for(int i=0; i<50; i++){
    // acceleration
    accelerationOffsetAccumulator += getAccRawValues();
    // gyro
    gyroOffsetAccumulator += getGyrRawValues();
    delay(1);
}

// acceleration
accelerationOffsetAccumulator /= 50.f;
accelerationOffsetAccumulator.z -= 16384.0f;
accOffsetVal = accelerationOffsetAccumulator;
// gyro
gyrOffsetVal = gyroOffsetAccumulator / 50.f;

}_

Magnetometer does not respond

Hello,

I´ve a bit of an issue getting the Magnetometer up and running, but every else is working fine.
I´ve 2 equal MPU9250 ( those blue one´s ), one of them is working fine, but the secound one seems like the Magnetometer is not responding...
After hours of googling and trying, but of course nothing is working and now I don´t know what to do...
I have tried setting the pass through i2c but 0x37 -> 0x02 , but it wont work, unfortunately.
Any idea what I cant try next?

Thank you in advance.

I changed the code a bit for testing purposes.

Main:

#include <Arduino.h>
#include <MPU9250_WE.h>
#include <Wire.h>
#define MPU9250_ADDR 0x68

MPU9250_WE myMPU9250 = MPU9250_WE(MPU9250_ADDR);

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  delay(2000);
  if (!myMPU9250.init())
  {
    Serial.println("MPU9250 does not respond");
  }
  else
  {
    Serial.println("MPU9250 is connected");
  }

  myMPU9250.enableGyrDLPF();
  myMPU9250.setGyrDLPF(MPU9250_DLPF_6); // lowest noise
  myMPU9250.setGyrRange(MPU9250_GYRO_RANGE_250);
  myMPU9250.setAccRange(MPU9250_ACC_RANGE_2G);
  myMPU9250.enableAccDLPF(true);
  myMPU9250.setAccDLPF(MPU9250_DLPF_6); // lowest noise

  if (!myMPU9250.initMagnetometer())
  {
    Serial.println("Magnetometer does not respond T-T ");
  }
  else
  {
    Serial.println("Magnetometer is connected");
  }
  delay(1000);
}

void loop()
{

  /*
    xyzFloat accRaw;
  xyzFloat gyrRaw;
  xyzFloat mgrRaw;
  accRaw = myMPU9250.getAccRawValues();
  gyrRaw = myMPU9250.getGyrRawValues();
  mgrRaw = myMPU9250.getMagValues();
  Serial.print(accRaw.x);
  Serial.print(";");
  Serial.print(accRaw.y);
  Serial.print(";");
  Serial.print(accRaw.z);
  Serial.print(";");
  Serial.print(gyrRaw.x);
  Serial.print(";");
  Serial.print(gyrRaw.y);
  Serial.print(";");
  Serial.print(gyrRaw.z);
  Serial.print(";");
  Serial.print(mgrRaw.x);
  Serial.print(";");
  Serial.print(mgrRaw.y);
  Serial.print(";");
  Serial.println(mgrRaw.z);

  */
}

I added some prints for the returning values for debuging in the MPU9250_WE.cpp

/************** Magnetometer **************/

bool MPU9250_WE::initMagnetometer(){
    enableI2CMaster();
    resetMagnetometer();

    if (!(whoAmIMag() == MAGNETOMETER_WHO_AM_I_CODE))
    {
        Serial.print("In int_pin ");
        Serial.println(readMPU9250Register8(0x37), HEX);
        Serial.print("I am ");
        Serial.println(whoAmIMag(), HEX);
        return false;
    }
    Serial.print("In int_pin ");
    Serial.println(readMPU9250Register8(0x37), HEX);
    Serial.print("I am ");
    Serial.println(whoAmIMag(), HEX);

    setMagOpMode(AK8963_FUSE_ROM_ACC_MODE);
    delay(10);
    getAsaVals();
    delay(10);
    setMagnetometer16Bit();
    delay(10);
    setMagOpMode(AK8963_CONT_MODE_8HZ);
    delay(10);

    return true;
}

Serial out put from the working IMU

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4
MPU9250 is connected
In int_pin 2
I am 48
Magnetometer is connected

Serial out put from the NOT working IMU

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4
MPU9250 is connected 
In int_pin 2
I am 0
Magnetometer does not respond T-T
ets Jul 29 2019 12:21:46

wake-on-motion interrupt not working as intended

Hello, I tried running the wom interrupt example code but i'm not getting the expected output. The loop is printing the readings correctly but whenever there is a motion the "Interrupt type: motion" is not detected for some reason. The if loop is not being executed, i think.

if(motion){
    byte source = myMPU9250.readAndClearInterrupts();
    Serial.println("Interrupt!");
    if(myMPU9250.checkInterrupt(source, MPU9250_WOM_INT)){
      Serial.println("Interrupt Type: Motion");
      delay(1000);
    }
    motion = false;
    // if additional interrupts have occured in the meantime:
    myMPU9250.readAndClearInterrupts(); 
  }

Also, I'm trying the low-pwr accel mode which will start taking readings when an interrupt is generated...board used is xiao nrf52840 by seeed studio

#include <MPU9250_WE.h>
#include <Wire.h>

#define MPU9250_ADDR 0x68

const int intPin = 2;
volatile bool motion = false;

MPU9250_WE myMPU9250 = MPU9250_WE(MPU9250_ADDR);

void setup() {
  Serial.begin(115200);

  while(!Serial) delay(10);
  Wire.begin();

  if (!myMPU9250.init()) {
    Serial.println("MPU9250 does not respond");
  } else {
    Serial.println("MPU9250 is connected");
  }
  
  Serial.println("Position your MPU9250 flat and don't move it - calibrating...");
  delay(1000);
  myMPU9250.autoOffsets();
  Serial.println("Done!");

  myMPU9250.setSampleRateDivider(5);

  // Configure accelerometer range
  myMPU9250.setAccRange(MPU9250_ACC_RANGE_2G);

  myMPU9250.enableAccDLPF(true);
  // *   DLPF     Bandwidth [Hz]      Delay [ms]    Output rate [kHz]
  // *     6             5              66.96           1
  myMPU9250.setAccDLPF(MPU9250_DLPF_6);
  
  // Set low power accelerometer data rate
  myMPU9250.setLowPowerAccDataRate(MPU9250_LP_ACC_ODR_0_98);
  
  // Enable motion detection interrupt
  myMPU9250.setIntPinPolarity(MPU9250_ACT_HIGH); // Set interrupt pin to active high

  myMPU9250.enableIntLatch(true);   

  myMPU9250.enableClearIntByAnyRead(false); 

  // Enable Wake-on-Motion (WoM) interrupt
  myMPU9250.enableInterrupt(MPU9250_WOM_INT);

  myMPU9250.setWakeOnMotionThreshold(128); // Set motion detection threshold

  /*  Enable/disable wake on motion (WOM) and  WOM mode:
   *  MPU9250_WOM_DISABLE
   *  MPU9250_WOM_ENABLE
   *  ***
   *  MPU9250_WOM_COMP_DISABLE   // reference is the starting value
   *  MPU9250_WOM_COMP_ENABLE    // reference is the last value
   */
  myMPU9250.enableWakeOnMotion(MPU9250_WOM_ENABLE, MPU9250_WOM_COMP_DISABLE);
  
  // Put MPU9250 to sleep
  // myMPU9250.sleep(true);
  // Serial.println("MPU9250 is in sleep mode. Waiting for motion to wake it up...");

  attachInterrupt(digitalPinToInterrupt(intPin), motionISR, RISING);
  Serial.println("Turn your MPU9250 and see what happens...");
}

void loop() {
  xyzFloat gValue, accRaw;

  if(motion){
    motion = false;
    // myMPU9250.sleep(false);
    
    // Read accelerometer data
    xyzFloat accRaw = myMPU9250.getAccRawValues();
    xyzFloat gValue = myMPU9250.getGValues();
    float resultantG = myMPU9250.getResultantG(gValue);

    // Print the accelerometer data
    Serial.println("Motion detected!");
    Serial.print("Raw acceleration values (x,y,z): ");
    Serial.print(accRaw.x);
    Serial.print(", ");
    Serial.print(accRaw.y);
    Serial.print(", ");
    Serial.println(accRaw.z);
    
    Serial.print("g values (x,y,z): ");
    Serial.print(gValue.x);
    Serial.print(", ");
    Serial.print(gValue.y);
    Serial.print(", ");
    Serial.println(gValue.z);

    Serial.print("Resultant g: ");
    Serial.println(resultantG);

    // delay(1000);

    // Clear any additional interrupts that may have occurred
    myMPU9250.readAndClearInterrupts();
    // myMPU9250.sleep(true);
  }
delay(10);
}

void motionISR() {
  motion = true;
  // myMPU9250.sleep(false);
}

o/p:
MPU9250 does not respond
Position your MPU9250 flat and don't move it - calibrating...
Done!
Turn your MPU9250 and see what happens...

Magnetometer as Compass

I am using the libraries for a project with arduino; the magnetometer works however it gives me values that are not accurate. I would like to know if it is possible to calibrate the magnetometer (without using the 8 movement) to make it more accurate so that I can then use it as a compass.

Possible bug inside the check part

Hi Wolfgang Ewald,

Noticed an unexpected behaviour inside the

if(!myMPU9250.init()){
    Serial.println("MPU9250 does not respond");
}
  else{
    Serial.println("MPU9250 is connected");
}

part of the examples.

For some reason the WHO_AM_I register of the MPU6500 unit on my MPU92/65 board returns 0x73 instead of 0x70 and thus the sketches always returned "MPU9250 does not respond" message when my board boots up, but this left unnoticed as regardless of this all subsequent register reads/writes were successful. After changing
static float constexpr WHO_AM_I_CODE = 0x70; to static float constexpr WHO_AM_I_CODE = 0x73;
insideMPU6500_WE.h the check is working almost as expected. By almost i mean it works great until i am initializing an MPU6500 object. In that case MPU6500_WE::whoAmI() member function will return 0x73 that gets compared to expectedValue inside MPU6500_WE::init(uint8_t const expectedValue). However if one initializes an MPU9250 object (like the MPU9250_acceleration_data example does), then it will compare the value stored in register No.117 (WHO_AM_I register) of the MPU6500 unit to the WHO_AM_I_CODE defined inside MPU9250_WE.h, which is 0x71. Thus the check function will always evaluate as false.

Took a look inside the documentation of the registers of the MPU9250 found here. It turns out, the magnetometer (AK8963) does not even have a WHO_AM_I register. So there is no register value against which we could compare 0x71 defined as WHO_AM_I_CODE for the magnetometer inside MPU9250_WE.h.

All this is not a big issue as any subsequent register reads/writes do what they are expected to do, just renders the current check part meaningless in its current form.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.