hideakitai / MPU9250

Arduino library for MPU9250 Nine-Axis (Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device
MIT License
279 stars 92 forks source link

Questions about the 25 ms interval #82

Closed hsiachi closed 2 years ago

hsiachi commented 2 years ago

Environment

IDE (Arduino IDE, PlatformIO, etc.) : Arduino IDE Board/MCU (Arduino Uno, ESP32, etc.): Arduino Nano Board Firmware Version (see board manager): Arduino AVR Boards v1.8.5 MPU-9250 Library Version: v0.4.8

Problem Summary

I'm using the library with its calibration, but I notice that if I comment out the 25 ms interval, quaternions will not be updated (More specifically it's 1, 0, 0, 0). This problem would not occur in simple Example.

Problem Details

Using the simple_with_calibration example works well, but if I comment out the 25 ms interval (as below), the quaternion will not get updated and holds to the value (1, 0, 0, 0). I notice there's no interval in simple example and I wonder what's the difference between these two.

    if (mpu.update()) {
        print_quaternion(); // simply get the quaternion and print out
        // static uint32_t prev_ms = millis();
        // if (millis() > prev_ms + 25) {
        //     print_quaternion();
        //     prev_ms = millis();
        }
    }

Reproducible & Minimal & Compilable Code

#include "MPU9250.h"

MPU9250 mpu;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    delay(2000);

    if (!mpu.setup(0x68)) {  // change to your own address
        while (1) {
            Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
            delay(5000);
        }
    }

    // calibrate anytime you want to
    Serial.println("Accel Gyro calibration will start in 5sec.");
    Serial.println("Please leave the device still on the flat plane.");
    mpu.verbose(true);
    delay(5000);
    mpu.calibrateAccelGyro();

    Serial.println("Mag calibration will start in 5sec.");
    Serial.println("Please Wave device in a figure eight until done.");
    delay(5000);
    mpu.calibrateMag();

    mpu.verbose(false);
}

void loop() {
    if (mpu.update()) {
        print_quaternion();
    }
}

void print_quaternion() {
    Serial.print("Quaterion: ");
    Serial.print(mpu.getQuaternionX(), 2);
    Serial.print(", ");
    Serial.print(mpu.getQuaternionY(), 2);
    Serial.print(", ");
    Serial.print(mpu.getQuaternionZ(), 2);
    Serial.print(", ");
    Serial.print(mpu.getQuaternionW(), 2);
    Serial.println();
}
hideakitai commented 2 years ago

Hi, could you fill the issue template, please?

hsiachi commented 2 years ago

Hi, could you fill the issue template, please?

I've updated with the issue template now :)

hideakitai commented 2 years ago

Could you give me "Reproducible & Minimal & Compilable Code" if you modified my example? I don't know what print_quaternion is.

hsiachi commented 2 years ago

Certainly. Sorry for bothering you

hsiachi commented 2 years ago

I figured out that it's because I've changed the baud rate to 9600 bits/sec (which I didn't notice). The sensor runs at 200 Hz, and printing a quaternion just exceeds the limit (while printing Euler Angles does not). Changing to 115200 bits/sec solves my problem. Sorry again for taking your time.