adafruit / Adafruit_CircuitPython_TMP117

CircuitPython library for the TI TMP117 Temperature sensor
MIT License
3 stars 4 forks source link

Single measurement test example eventually stops working #10

Open hopkapi opened 2 years ago

hopkapi commented 2 years ago

Once any of the tmp117.averaged_measurements lines are uncommented (seemingly other than the first, which is an average of 1) in the example code, the example code runs for an inconsistent amount of time, but eventually stops supplying new data.

The rate and averaging test seems to work fine.

Tested with two TMP117 breakouts with different Stemma QT cables, on both a Feather M4 and a Feather ESP32-S2 TFT, both with the latest 7.x of CP for each.

Rob192 commented 2 years ago

I have the same issue on my side. I tested with the TMP117 breakout board from adafruit and bluefruit feather NRF52

ladyada commented 2 years ago

what if you dont use averaged_measurements and just the basic temp data reading? https://github.com/adafruit/Adafruit_CircuitPython_TMP117/blob/main/examples/tmp117_simpletest.py

adriangalilea commented 1 year ago

take_single_measurement doesn't seem to work as intended.

Tested with different combinations of 'averaged_measurements' and 'measurement_delay' and the only one I think works is default delay and increased average, but once I increase delay to let's say "MeasurementDelay.DELAY_1_S" and "AverageCount.AVERAGE_8X" reads are instant and it eventually crashes if in a loop.

Expected behaviour based on documentation is "Note: if averaged_measurements is set to a high value there will be a notable delay before the temperature measurement is returned while the sensor takes the required number of measurement"

jposada202020 commented 1 year ago

Hello :).

Some considerations:

  1. Not sure what is happening with the crashes, maybe you could provide an error traceback info that we could use?

  2. When we use the sensor in One shot mode, the sensor will take the average_measurement value into account. However, this measure is done with the formula (15.5 ms × average_time), so in normal operation average_time will be 8, therefore time for measure is 124 ms. (See datasheet. 7.3.2 Averaging for more information). If we use 64, time will be 15.5 x 65 = 992 ms, the standby time will decrease, but the measure is still under 1 Hz cycle. (See Fig 7.2 on the datasheet)

  3. Once the measure is done, the sensor will not return a new temperature value, until de measurement_mode is set again. As described in https://github.com/adafruit/Adafruit_CircuitPython_TMP117/blob/61b409809cd01c8a72c66670ab4ac78192f34f18/adafruit_tmp117.py#L380-L393 To verify this behaviour, please use the modified script provided below:

# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import board
from adafruit_tmp117 import TMP117, AverageCount, MeasurementMode
import time

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
tmp117 = TMP117(i2c)

# uncomment different options below to see how it affects the reported temperature
# and measurement time
# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
tmp117.averaged_measurements = AverageCount.AVERAGE_64X

print(
    "Number of averaged samples per measurement:",
    AverageCount.string[tmp117.averaged_measurements],
)
print(
    "Reads should take approximately",
    AverageCount.string[tmp117.averaged_measurements] * 0.0155,
    "seconds",
)

while True:
    print("Single measurement: %.2f degrees C" % tmp117.take_single_measurement())
    for i in range(10):
        print("One Shot Measurement mode: ", tmp117.measurement_mode)
        print("Temperature: ", tmp117.temperature)
        time.sleep(1)
    tmp117.measurement_mode = MeasurementMode.CONTINUOUS
    for i in range(10):
        print("Temperature: ", tmp117.temperature)
        print("Continuos Measurement Mode: ",  tmp117.measurement_mode)
        time.sleep(1)
  1. Note that the temperature resolution according to the datasheet: "the temperature result output has a repeatability of approximately ±3 LSBs when there is no averaging and ±1 LSB when the device is configured to perform eight averages" So you could see small variation in the temperature.

  2. Maybe we could improve documentation to better explain this behaviour, what do you think @adriangalilea?

  3. Let me know if I am missing something, happy to test on my side too :)