Skip to content

Bug: returning magnetometer values in wrong order | Fixed incorrect return order in _raw_magnetic. #16

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

Closed
wants to merge 1 commit into from

Conversation

Arduino3128
Copy link

Hi,
Just noticed the values that are being returned from _raw_magnetic function are in wrong order:

return (raw_values[0], raw_values[2], raw_values[1])

According to the datasheet of LSM303DLH, the register 0x03-0x04 is for X channel, 0x05-0x06 for Y channel and 0x07-0x08 for Z channel.
image

The address of the registers Y and Z are also interchanged in the declaration, which could have given the correct output, but it looks like the library is fetching readings from all 6 registers simultaneously and not though the defined addresses in line 51 to 54:

self._read_bytes(self._mag_device, _REG_MAG_OUT_X_H_M, 6, self._BUFFER)

_REG_MAG_OUT_X_H_M = const(0x03)
_REG_MAG_OUT_X_L_M = const(0x04)
_REG_MAG_OUT_Z_H_M = const(0x05)
_REG_MAG_OUT_Z_L_M = const(0x06)
_REG_MAG_OUT_Y_H_M = const(0x07)
_REG_MAG_OUT_Y_L_M = const(0x08)

Hence while returning it is returning in order X,Z,Y.

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository is actually for the LSM303DLHC, where the registers are actually correct as is:

https://cdn-shop.adafruit.com/datasheets/LSM303DLHC.PDF

I'm going to close this since it's not actually a driver problem but a documentation problem. I'll create an issue for specifying that this is NOT the LSM303DLH proper, for which your changes are correct. If you want to tackle that change to help make that distinction more apparent, go for it!

@tekktrik tekktrik closed this Sep 27, 2022
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

Successfully merging this pull request may close these issues.

2 participants