Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magnetometer readings are incorrect - byte order issue #23

Open
konkrog opened this issue Sep 12, 2020 · 1 comment
Open

Magnetometer readings are incorrect - byte order issue #23

konkrog opened this issue Sep 12, 2020 · 1 comment

Comments

@konkrog
Copy link

konkrog commented Sep 12, 2020

The code for magnetometer reading must be fixed. The byte order is incorrect according to datasheet. The code should read:

`/**

  • @brief Read readings from magnetometer.
    */
    void MPU9255::read_mag()
    {
    requestBytes(MAG_address, MAG_XOUT_L, 8);//note we must request 8 bytes of data because otherwise it does not work

uint8_t rawData[6];
readArray(rawData,6);

mx = ((int16_t)rawData[1] << 8) | rawData[0];
my = ((int16_t)rawData[3] << 8) | rawData[2];
mz = ((int16_t)rawData[5] << 8) | rawData[4];
}
`

MaartenJB added a commit to MaartenJB/MPU9255-Arduino-Library that referenced this issue Nov 1, 2022
@MaartenJB
Copy link

MaartenJB commented Nov 1, 2022

thanks konkrog for posting, this fixed the issue. I've made a pull request for the library owner.

For anyone who want the fixed version until the maintainer of this library fixed the problem, you can you the fixed version:

https://github.com/MaartenJB/MPU9255-Arduino-Library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants