Skip to content

Purposed Version 1.1.0 - Temperature Sensor Support #12

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

Merged
merged 9 commits into from
May 15, 2023

Conversation

iLikePieTM
Copy link
Contributor

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 :)

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

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

@iLikePieTM
Copy link
Contributor Author

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

Co-Authored-By: per1234 <[email protected]>
@cansik
Copy link

cansik commented Jun 18, 2020

Will this be merged soon?

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

@karlsoderby
Copy link
Contributor

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

@J1mbo
Copy link

J1mbo commented Jun 2, 2022

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

+1!

@isyca
Copy link

isyca commented Oct 10, 2022

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

@oliverswitzer
Copy link

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.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels May 5, 2023
@per1234 per1234 linked an issue May 5, 2023 that may be closed by this pull request
@iLikePieTM
Copy link
Contributor Author

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.

@github-actions
Copy link

github-actions bot commented May 5, 2023

Memory usage change @ 1a874c5

Board flash % RAM for global variables %
arduino:megaavr:uno2018 🔺 +156 - +156 +0.32 - +0.32 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 🔺 +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

@oliverswitzer
Copy link

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

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

@per1234
Copy link
Contributor

per1234 commented May 5, 2023

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

@facchinm facchinm merged commit 7aa9165 into arduino-libraries:master May 15, 2023
@facchinm
Copy link
Contributor

Merged, thanks for your contribution!

@oliverswitzer
Copy link

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

@oliverswitzer
Copy link

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?

@ryanohoro
Copy link

@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.

@per1234 per1234 mentioned this pull request Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access on-chip temperature sensor
10 participants