Arduino_LSM6DS3 icon indicating copy to clipboard operation
Arduino_LSM6DS3 copied to clipboard

Purposed Version 1.1.0 - Temperature Sensor Support

Open iLikePieTM opened this issue 4 years ago • 6 comments

I would like to propose a version 1.1.0 update to the library that adds support for the LSM6DS3's integrated temperature sensor with three new functions:

  • readTemp outputs the temperature reading in deg. C and returns 1 if successful

  • tempSampleRate returns the sampling rate of the sensor

  • tempAvailable returns 1 if there is available data from the temperature sensor

P.S. first time doing this so don't be too harsh :)

iLikePieTM avatar Mar 15 '20 23:03 iLikePieTM

Consider using readTemperature, temperatureAvailable, temperatureSampleRate to make the code more self-documenting. "temp" might be short for "temporary".

Please add the new function names to keywords.txt. Use a true tab to separate the function name from the identifier: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywordstxt-format

Thanks for the feedback!

  • I implemented the self-documenting suggestion; I tend to use abbreviations but there's no reason not to be descriptive. I also updated the keywords file.

  • Sorry for getting a bit ahead of myself with the revision number changes too :P

iLikePieTM avatar Mar 17 '20 15:03 iLikePieTM

Will this be merged soon?

cansik avatar Jun 18 '20 13:06 cansik

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 09 '21 14:04 CLAassistant

@iLikePieTM it seems your PR was approved long time ago, will it be merged soon? 😄 (this is a great feature)

karlsoderby avatar Jun 02 '22 13:06 karlsoderby

@iLikePieTM it seems your PR was approved long time ago, will it be merged soon? 😄 (this is a great feature)

+1!

J1mbo avatar Jun 02 '22 17:06 J1mbo

very useful to have and hope this gets merged. worked well with Nano 33 IoT

a little suggestion if I may, to follow LSM6DSOXClass::readTemperature and LSM6DSOXClass::readTemperatureFloat from Arduino_LSM6DSOX that way we have int and float

isyca avatar Oct 10 '22 22:10 isyca

Would love to bump this, since all checks have passed and its been approved. This would be immensely helpful to have on my current project.

oliverswitzer avatar May 04 '23 18:05 oliverswitzer

It's been years and I totally forgot about this lol. I fixed the conflicts with the current master branch, it's ready to merge by someone with write access.

iLikePieTM avatar May 05 '23 14:05 iLikePieTM

Memory usage change @ 1a874c537a3cddd13525186a8d186597dc05da62

Board flash % RAM for global variables %
arduino:megaavr:uno2018 :small_red_triangle: +156 - +156 +0.32 - +0.32 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot :small_red_triangle: +108 - +108 +0.04 - +0.04 0 - 0 0.0 - 0.0
Click for full report table
Board examples/SimpleAccelerometer
flash
% examples/SimpleAccelerometer
RAM for global variables
% examples/SimpleGyroscope
flash
% examples/SimpleGyroscope
RAM for global variables
% examples/SimpleTempSensor
flash
% examples/SimpleTempSensor
RAM for global variables
%
arduino:megaavr:uno2018 156 0.32 0 0.0 156 0.32 0 0.0 N/A N/A N/A N/A
arduino:samd:nano_33_iot 108 0.04 0 0.0 108 0.04 0 0.0 N/A N/A N/A N/A
Click for full report CSV
Board,examples/SimpleAccelerometer<br>flash,%,examples/SimpleAccelerometer<br>RAM for global variables,%,examples/SimpleGyroscope<br>flash,%,examples/SimpleGyroscope<br>RAM for global variables,%,examples/SimpleTempSensor<br>flash,%,examples/SimpleTempSensor<br>RAM for global variables,%
arduino:megaavr:uno2018,156,0.32,0,0.0,156,0.32,0,0.0,N/A,N/A,N/A,N/A
arduino:samd:nano_33_iot,108,0.04,0,0.0,108,0.04,0,0.0,N/A,N/A,N/A,N/A

github-actions[bot] avatar May 05 '23 14:05 github-actions[bot]

@iLikePieTM thanks for the quick response! Really excited to make use of this.

@per1234 any chance this could get a second review / a merge?

oliverswitzer avatar May 05 '23 16:05 oliverswitzer

Hello all. Thanks @iLikePieTM for your pull request and also to @oliverswitzer for your interest in this open source project.

My role in this project is essentially janitorial. I am not in a role to merge changes to the library codebase. One of the projects other maintainers will make that decision.

Regards, Per

per1234 avatar May 05 '23 16:05 per1234

Merged, thanks for your contribution!

facchinm avatar May 15 '23 07:05 facchinm

Thanks for merging @facchinm! Any sense of when the next release will be?

oliverswitzer avatar May 15 '23 13:05 oliverswitzer

Hi @iLikePieTM,

I am trying to use this functionality now, but am consistently getting temperature readings that seem like they're too high considering that the board is sitting at ambient room temperature (75 degrees F):

float temp = 0;

...

  if (IMU.temperatureAvailable()) {
    IMU.readTemperature(_lastTemp);
    IMU.readTemperature(temp);
    Serial.println("*********** TEMP: " + String(temp));
  }

Output (over a few seconds):

********** TEMP: 133.88
*********** TEMP: 130.81
*********** TEMP: 133.38
*********** TEMP: 132.06
*********** TEMP: 131.69
*********** TEMP: 129.25
*********** TEMP: 133.56
*********** TEMP: 132.88
*********** TEMP: 130.56
*********** TEMP: 132.75
*********** TEMP: 130.12
*********** TEMP: 130.69
*********** TEMP: 132.44
*********** TEMP: 133.94
*********** TEMP: 130.69
*********** TEMP: 134.56
*********** TEMP: 130.75
*********** TEMP: 131.94
*********** TEMP: 133.19
*********** TEMP: 130.38
*********** TEMP: 133.38
*********** TEMP: 131.88
*********** TEMP: 132.00
*********** TEMP: 133.44
*********** TEMP: 132.56
*********** TEMP: 131.50
*********** TEMP: 130.81
*********** TEMP: 132.19

Any idea why this temp seems so high?

oliverswitzer avatar Jun 16 '23 20:06 oliverswitzer

@oliverswitzer

I ran into a similar problem with my Nano 33 IoT. Running the SimpleTempSensor example code for this library caused non-sensible results.

Temperature sensor sample rate = 52.00 Hz

Temperature reading in degrees C
T
123.12
126.44
126.00
127.25
128.56

Reading the source code for the Adafruit_CircuitPython_LSM6DS library for this sensor reveals the formula for converting the raw temperature value to Celsius is probably the culprit. The Adafruit makes a similar assumption, that all the chips in this family have the same temperature parameters.

https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS/blob/c4d6b88c5d537e0ba6b430987ccb2020475dc2e5/adafruit_lsm6ds/init.py#L394

Arduino_LSM6DS3 library uses t = data[0] / 16.0 + 25; and Adafruit_CircuitPython_LSM6DS uses t = data[0] / 256 + 25.0;

The datasheet for the LSM6DS3 has a temperature sensitivity of 16 (Table 4.3)

https://content.arduino.cc/assets/st_imu_lsm6ds3_datasheet.pdf (SH)

The datasheets for the LSM6D3-C/LSM6DST/LSM6DSL/LSM6DSO/LSM6DSOX have a temperature sensitivity of 256 (Table 4.3)

https://www.st.com/resource/en/datasheet/lsm6ds3tr-c.pdf (SE) https://www.st.com/resource/en/datasheet/lsm6dst.pdf https://www.st.com/resource/en/datasheet/lsm6dsl.pdf https://www.st.com/resource/en/datasheet/lsm6dso.pdf https://www.st.com/resource/en/datasheet/lsm6dsox.pdf (S4)

Changing this library's temperature sensitivity value to 256 outputs values that I confirmed with an infrared thermometer are accurate:

Temperature sensor sample rate = 52.00 Hz

Temperature reading in degrees C
T
26.95
26.83
26.79
26.95
26.95

I suspect Arduino shipped the Nano 33 IoT with undocumented LSM6DS3 compatible variants because LSM6DS3 is an obsolete part, and it likely didn't affect the IMU function. However, it seems all the new parts in the family have higher temperature sensitivity. The S4 marking on my chip suggests it's a LSM6DSOX. Photos on the Arduino website show SH markings, the LSM6DS3. The SH and S4 markings are hard to distinguish, bit I'm confident mine is S4.

image

20231207_004442

33iot012

https://learn.adafruit.com/lis3mdl-triple-axis-magnetometer

sensors_ISO_crop

@iLikePieTM Seems like it's going to look like this function is randomly broken unless the IMU temperature sensitivity can be programmatically determined.

ryanohoro avatar Dec 07 '23 08:12 ryanohoro