MPU9255-Arduino-Library
MPU9255-Arduino-Library copied to clipboard
Magnetometer readings are incorrect - byte order issue
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]; } `
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