MPU9250 gyroscope

Hello everyone,
I was just wondering why this piece of code is not working. Here are the code and the circuit down below.

#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();

    print_calibration();
    mpu.verbose(false);
}

void loop() {
}

void print_calibration() {
    Serial.println("< calibration parameters >");
    Serial.println("accel bias [g]: ");
    Serial.print(mpu.getAccBiasX() * 1000.f / (float)MPU9250::CALIB_ACCEL_SENSITIVITY);
    Serial.print(", ");
    Serial.print(mpu.getAccBiasY() * 1000.f / (float)MPU9250::CALIB_ACCEL_SENSITIVITY);
    Serial.print(", ");
    Serial.print(mpu.getAccBiasZ() * 1000.f / (float)MPU9250::CALIB_ACCEL_SENSITIVITY);
    Serial.println();
    Serial.println("gyro bias [deg/s]: ");
    Serial.print(mpu.getGyroBiasX() / (float)MPU9250::CALIB_GYRO_SENSITIVITY);
    Serial.print(", ");
    Serial.print(mpu.getGyroBiasY() / (float)MPU9250::CALIB_GYRO_SENSITIVITY);
    Serial.print(", ");
    Serial.print(mpu.getGyroBiasZ() / (float)MPU9250::CALIB_GYRO_SENSITIVITY);
    Serial.println();
    Serial.println("mag bias [mG]: ");
    Serial.print(mpu.getMagBiasX());
    Serial.print(", ");
    Serial.print(mpu.getMagBiasY());
    Serial.print(", ");
    Serial.print(mpu.getMagBiasZ());
    Serial.println();
    Serial.println("mag scale []: ");
    Serial.print(mpu.getMagScaleX());
    Serial.print(", ");
    Serial.print(mpu.getMagScaleY());
    Serial.print(", ");
    Serial.print(mpu.getMagScaleZ());
    Serial.println();
}

And here's the error.

In file included from C:\Users\...\Documents\Arduino\libraries\MPU9250/MPU9250.h:5:0,
                 from C:\Users\...\Documents\Arduino\prova\prova.ino:1:
C:\Users\...\Documents\Arduino\libraries\MPU9250/MPU9250.h: In instantiation of 'void MPU9250_<WireType>::read_bytes(uint8_t, uint8_t, uint8_t, uint8_t*) [with WireType = TwoWire; uint8_t = unsigned char]':
C:\Users\...\Documents\Arduino\libraries\MPU9250/MPU9250.h:428:19:   required from 'void MPU9250_<WireType>::initAK8963() [with WireType = TwoWire]'
C:\Users\...\Documents\Arduino\libraries\MPU9250/MPU9250.h:143:27:   required from 'bool MPU9250_<WireType>::setup(uint8_t, const MPU9250Setting&, WireType&) [with WireType = TwoWire; uint8_t = unsigned char]'
C:\Users\...\Documents\Arduino\prova\prova.ino:10:24:   required from here
C:\Users\...\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:63:12: note: candidate 1: size_t TwoWire::requestFrom(int, int)
     size_t requestFrom(int, int);
            ^~~~~~~~~~~
C:\Users\...\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:61:12: note: candidate 2: virtual size_t TwoWire::requestFrom(uint8_t, size_t)
     size_t requestFrom(uint8_t, size_t);
            ^~~~~~~~~~~

The library I'm using right now is from "hideakitai" 0.4.8 version.

Please have a look at the "How to get the best out of this forum" post, and replace the picture of code with code posted properly, using code tags.

Also explain what "not working" means. Described what did you expected to happen, and what happened instead.

Thank you!

Please post your complete sketch (just in case, don't forget the code tags as described in How to get the best out of this forum).

I suspect that the MPU9050 library was written for AVR based boards like the classic Nano and was not updated to cater for the megaAVR boards (like the 4809 on the Nano Evevry). Please indicate which library you exactly installed.


Your topic does not indicate a problem with the IDE (and you're using IDE 2.x, not IDE 1.x :wink) and hence has been moved to a more suitable location on the forum.

For the compatibility it says " This library is compatible with all architectures so you should be able to use it on all the Arduino boards."

I asked for a link to the library. A link to the page where you found the info from post #5 is also OK.

Whatever the library states, it seems to be incorrect.

Thanks, I did find it in the meantime as well :wink:

It's a warning, not an error and it will, as far as I can see, not affect the functioning of the program.

If you want to fix it:

These are the 4 requestFrom() methods in the Wire library for thre megaAVR

    size_t requestFrom(uint8_t, size_t);
    size_t requestFrom(uint8_t, size_t, bool);
    size_t requestFrom(int, int);
    size_t requestFrom(int, int, int);

This is the method in the MPU9250 library that the compiler complains about

    void read_bytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest) {
        wire->beginTransmission(address);         // Initialize the Tx buffer
        wire->write(subAddress);                  // Put slave register address in Tx buffer
        i2c_err_ = wire->endTransmission(false);  // Send the Tx buffer, but send a restart to keep connection alive
        if (i2c_err_) print_i2c_error();
        uint8_t i = 0;
        wire->requestFrom(address, count);  // Read bytes from slave register address
        while (wire->available()) {
            dest[i++] = wire->read();
        }  // Put read results in the Rx buffer
    }

and specifically the line wire->requestFrom(address, count) (line 993); there is no method in the Wire library that exactly matches two arguments of type uint8_t (address and count). You will need to cast.

You can replace the offending line in the MPU9250 library (file
C:\Users...\Documents\Arduino\libraries\MPU9250/MPU9250.h)
by wire->requestFrom(address, (size_t)count); // Read bytes from slave register address

After that change, those warnings will be gone because the compiler can now exactly identify which method to use.

Note:
I have forgotten to test if this affects the AVR boards like the classic Nano. You can test this yourself by just compiling for the classic Nano or an Uno.