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

fix: correct calc to uT based on res and gain. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Adafruit_MLX90395.cpp
Original file line number Diff line number Diff line change
@@ -56,8 +56,10 @@ bool Adafruit_MLX90395::_init(void) {
_gain = getGain();
if (_gain == 8) { // default high field gain
_uTLSB = 7.14;
_gain_default = 8;
} else {
_uTLSB = 2.5; // medium field gain
_gain_default = 9;
}

_resolution = getResolution();
@@ -121,14 +123,15 @@ bool Adafruit_MLX90395::readMeasurement(float *x, float *y, float *z) {
yi = (rx[4] << 8) | rx[5];
zi = (rx[6] << 8) | rx[7];

*x = xi;
*y = yi;
*z = zi;
// makes a resolution correction, see DS 18.6. Sensitivity for details
*x = (float)(xi << _resolution);
*y = (float)(yi << _resolution);
*z = (float)(zi << _resolution);

// multiply by gain & LSB
*x *= gainMultipliers[_gain] * _uTLSB;
*y *= gainMultipliers[_gain] * _uTLSB;
*z *= gainMultipliers[_gain] * _uTLSB;
// multiply by current gain setting & LSB/uT
*x *= _uTLSB * gainMultipliers[_gain_default] / gainMultipliers[_gain];
*y *= _uTLSB * gainMultipliers[_gain_default] / gainMultipliers[_gain];
*z *= _uTLSB * gainMultipliers[_gain_default] / gainMultipliers[_gain];

return true;
}
1 change: 1 addition & 0 deletions Adafruit_MLX90395.h
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ class Adafruit_MLX90395 : public Adafruit_Sensor {

mlx90393_res_t _resolution = MLX90395_RES_17;
uint8_t _gain = 0;
uint8_t _gain_default = 0;
float _uTLSB = 0;
int32_t _sensorID = 90395;
};