0

I am using an Arduino Uno and learning to use the motion sensor. Currently I was not able to find the library which looks simple and would like to get your suggestion. I found this https://github.com/hideakitai/MPU9250 library to be simple but don't know how to use it.

For example, take this code:-

#include "MPU9250.h"

MPU9250 mpu;

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

    Wire.begin();

    delay(2000);
    mpu.setup();
}

void loop()
{
    static uint32_t prev_ms = millis();
    if ((millis() - prev_ms) > 16)
    {
        mpu.update();
        mpu.print();

        Serial.print("roll  (x-forward (north)) : ");
        Serial.println(mpu.getRoll());
        Serial.print("pitch (y-right (east))    : ");
        Serial.println(mpu.getPitch());
        Serial.print("yaw   (z-down (down))     : ");
        Serial.println(mpu.getYaw());

        prev_ms = millis();
    }
}

Some values are not defined here, like registration code and input pins. I am not used to reading the documentation code so might need help in that.

  • I didn't understand the docs – Sultan Morbiwala Feb 12 at 17:18
  • 1
    thanks for updating your post ..... you are asking the wrong question ..... you do not have a problem with the MPU9250 library ..... your problem is with I2C communication ..... arduino.cc/en/Reference/Wire – jsotola Feb 12 at 18:39
  • What is the problem here, are you getting any values? Yes, then good. Finding a simple solutions to complex problems isn't always a given. If it works, stick with it. If it doesn't work then show us the schematics? I would rely on this example since it's hiding all the logic. Until it's dis-proven. You can build a schematic here to show us. (tinkercad.com/circuits). The code should work, but i dont see any code for wiring. – Sigma Feb 13 at 20:56
2

In the Arduino IDE, click on SKETCH > INCLUDE LIBRARY > MANAGE LIBRARIES.

enter image description here

Then, search for 9250, select the SparkFun one, and click INSTALL.

enter image description here

Finally, from the examples, choose the MPU9250BasicAHRS_I2C.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.