adafruit / Adafruit_LSM6DS

Arduino library for LSM6DS
Other
47 stars 39 forks source link

Fix temperature calculation #23

Closed rotorman closed 3 years ago

rotorman commented 3 years ago

The original division factor of 256 was wrong for LSM6DS33 and caused the temperature to only change very close to offset value of +25 deg C. According to ST LSM6DS33 datasheet https://www.st.com/resource/en/datasheet/lsm6ds33.pdf page 18 Table 5 under TSen the correct divisor value of 16 is also given, although I have to admin this is not so clear as the unit is somewhat wrongly labeled LSB. What ST here means is, 16 digits equates to 1 degree, resulting the raw value required to be divided with 16 to add to offset of 25 degrees Celsius.

I tested the changed code with Adafruit LSM6DS33 (Product ID: 4480) https://www.adafruit.com/product/4480 and it produces correct temperature output in degrees Celsius.

Just to give you another reference source, where 16 is used, have a look at: https://os.mbed.com/users/bclaus/code/LSM6DS33//file/4e7d663e26bd/LSM6DS33.cpp/ LSM6DS33.cpp line 124

caternuson commented 3 years ago

The class layout in this library is like this:

LSM6DS
  |-LSM6DSL
  |-LSM6DS33
  |-LSM6DS3
  |-LSM6DSOX
      |-ISM330DHCX
      |-LSM6DSO32

The temperature computation is in the LSM6DS base class. So the general question is what is the temperature sensitivity for all the derived classes, with the LSM6DS33 being just one of them. Looking at the datasheets for each:

LSM6DSL (link) image

LSM6DS33 (link) image

LSM6DS3 (link) image

LSM6DSOX (link) image

While they all have the same 0 LSB = 25 C offset, the temperature sensitivity is mixed. Summary:

So this PR will fix it for the LSM6DS3 and LSM6DS33, but break it for the LSM6DSL and LSM6DSOX. Thanks for pointing this out. This is an issue, but just needs a slightly different approach to fixing. Looks like each derived class will need its own temperature sensitivity parameter.

rotorman commented 3 years ago

So this PR will fix it for the LSM6DS3 and LSM6DS33, but break it for the LSM6DSL and LSM6DSOX. Thanks for pointing this out. This is an issue, but just needs a slightly different approach to fixing. Looks like each derived class will need its own temperature sensitivity parameter.

Got it. After you have merged a correct fix applying to all LSM6DS variants, please feel free to close this PR without merging.

caternuson commented 3 years ago

Do you want to try and update this PR to add in the changes?

rotorman commented 3 years ago

As I have no other hw to test than LSM6DS33, it might be better that I leave it to you or someone who can also test before submitting this on other sensor ICs. Sorry for not seeing that some LSM6DS family members actually do use 256 as division factor.

caternuson commented 3 years ago

@rotorman Please try the 4.3.1 release of the library when it becomes available: https://github.com/adafruit/Adafruit_LSM6DS/releases/tag/4.3.1

rotorman commented 3 years ago

Just tested 4.3.1 with LSM6DS33 - works beautifully now. Thank you! Closing.

caternuson commented 3 years ago

Cool. Thanks for letting us know, and also pointing out the issue.