Simple test

Ensure your device works with this simple test.

examples/tmp117_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import time
 5import board
 6import adafruit_tmp117
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9tmp117 = adafruit_tmp117.TMP117(i2c)
10
11while True:
12    print("Temperature: %.2f degrees C" % tmp117.temperature)
13    time.sleep(1)

Temperature limits and alerts

Set high and low temperature limits and be alerted when they are surpassed.

examples/tmp117_limits_test.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import time
 5import board
 6from adafruit_tmp117 import TMP117, AlertMode
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9
10tmp117 = TMP117(i2c)
11
12tmp117.high_limit = 25
13tmp117.low_limit = 10
14
15print("\nHigh limit", tmp117.high_limit)
16print("Low limit", tmp117.low_limit)
17
18# Try changing `alert_mode`  to see how it modifies the behavior of the alerts.
19# tmp117.alert_mode = AlertMode.WINDOW #default
20# tmp117.alert_mode = AlertMode.HYSTERESIS
21
22print("Alert mode:", AlertMode.string[tmp117.alert_mode])
23print("\n\n")
24while True:
25    print("Temperature: %.2f degrees C" % tmp117.temperature)
26    alert_status = tmp117.alert_status
27    print("High alert:", alert_status.high_alert)
28    print("Low alert:", alert_status.low_alert)
29    print("")
30    time.sleep(1)

Measurement averaging and rate

Adjust the number of samples averaged for every reported temperature, and adjust the time beween new measurement reports

examples/tmp117_rate_and_averaging_test.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4# pylint:disable=no-member
 5
 6# This example is best viewed using a serial plotter
 7# such as the one built into the Mu editor.
 8import time
 9import board
10from adafruit_tmp117 import TMP117, AverageCount, MeasurementDelay
11
12i2c = board.I2C()  # uses board.SCL and board.SDA
13tmp117 = TMP117(i2c)
14
15# uncomment different options below to see how it affects the reported temperature
16# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
17# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
18# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
19# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
20
21# tmp117.measurement_delay = MeasurementDelay.DELAY_0_0015_S
22# tmp117.measurement_delay = MeasurementDelay.DELAY_0_125_S
23# tmp117.measurement_delay = MeasurementDelay.DELAY_0_250_S
24# tmp117.measurement_delay = MeasurementDelay.DELAY_0_500_S
25# tmp117.measurement_delay = MeasurementDelay.DELAY_1_S
26# tmp117.measurement_delay = MeasurementDelay.DELAY_4_S
27# tmp117.measurement_delay = MeasurementDelay.DELAY_8_S
28# tmp117.measurement_delay = MeasurementDelay.DELAY_16_S
29
30print(
31    "Number of averaged samples per measurement:",
32    AverageCount.string[tmp117.averaged_measurements],
33)
34print(
35    "Minimum time between measurements:",
36    MeasurementDelay.string[tmp117.measurement_delay],
37    "seconds",
38)
39print("")
40
41while True:
42    print("Temperature:", tmp117.temperature)
43    time.sleep(0.01)

Temperature offset

Set an offset that will be applied to each measurement, to account for measurement biases in the sensor’s environment

examples/tmp117_offset_test.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import time
 5import board
 6import adafruit_tmp117
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9
10tmp117 = adafruit_tmp117.TMP117(i2c)
11
12print("Temperature without offset: %.2f degrees C" % tmp117.temperature)
13tmp117.temperature_offset = 10.0
14while True:
15    print("Temperature w/ offset: %.2f degrees C" % tmp117.temperature)
16    time.sleep(1)

Single Measurement Test

Take different sample number and average to give a single temperature measure

examples/tmp117_single_measurement_test.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import board
 5from adafruit_tmp117 import TMP117, AverageCount
 6
 7i2c = board.I2C()  # uses board.SCL and board.SDA
 8tmp117 = TMP117(i2c)
 9
10# uncomment different options below to see how it affects the reported temperature
11# and measurement time
12
13# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
14# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
15# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
16# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
17
18print(
19    "Number of averaged samples per measurement:",
20    AverageCount.string[tmp117.averaged_measurements],
21)
22print(
23    "Reads should take approximately",
24    AverageCount.string[tmp117.averaged_measurements] * 0.0155,
25    "seconds",
26)
27
28while True:
29    print("Single measurement: %.2f degrees C" % tmp117.take_single_measurememt())
30    # time.sleep(1)