Simple test¶
Ensure your device works with this simple test.
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# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10tmp117 = adafruit_tmp117.TMP117(i2c)
11
12while True:
13 print("Temperature: %.2f degrees C" % tmp117.temperature)
14 time.sleep(1)
Temperature limits and alerts¶
Set high and low temperature limits and be alerted when they are surpassed.
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# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10
11tmp117 = TMP117(i2c)
12
13tmp117.high_limit = 25
14tmp117.low_limit = 10
15
16print("\nHigh limit", tmp117.high_limit)
17print("Low limit", tmp117.low_limit)
18
19# Try changing `alert_mode` to see how it modifies the behavior of the alerts.
20# tmp117.alert_mode = AlertMode.WINDOW #default
21# tmp117.alert_mode = AlertMode.HYSTERESIS
22
23print("Alert mode:", AlertMode.string[tmp117.alert_mode])
24print("\n\n")
25while True:
26 print("Temperature: %.2f degrees C" % tmp117.temperature)
27 alert_status = tmp117.alert_status
28 print("High alert:", alert_status.high_alert)
29 print("Low alert:", alert_status.low_alert)
30 print("")
31 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
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
13# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
14tmp117 = TMP117(i2c)
15
16# uncomment different options below to see how it affects the reported temperature
17# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
18# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
19# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
20# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
21
22# tmp117.measurement_delay = MeasurementDelay.DELAY_0_0015_S
23# tmp117.measurement_delay = MeasurementDelay.DELAY_0_125_S
24# tmp117.measurement_delay = MeasurementDelay.DELAY_0_250_S
25# tmp117.measurement_delay = MeasurementDelay.DELAY_0_500_S
26# tmp117.measurement_delay = MeasurementDelay.DELAY_1_S
27# tmp117.measurement_delay = MeasurementDelay.DELAY_4_S
28# tmp117.measurement_delay = MeasurementDelay.DELAY_8_S
29# tmp117.measurement_delay = MeasurementDelay.DELAY_16_S
30
31print(
32 "Number of averaged samples per measurement:",
33 AverageCount.string[tmp117.averaged_measurements],
34)
35print(
36 "Minimum time between measurements:",
37 MeasurementDelay.string[tmp117.measurement_delay],
38 "seconds",
39)
40print("")
41
42while True:
43 print("Temperature:", tmp117.temperature)
44 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
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# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10
11tmp117 = adafruit_tmp117.TMP117(i2c)
12
13print("Temperature without offset: %.2f degrees C" % tmp117.temperature)
14tmp117.temperature_offset = 10.0
15while True:
16 print("Temperature w/ offset: %.2f degrees C" % tmp117.temperature)
17 time.sleep(1)
Single Measurement Test¶
Take different sample number and average to give a single temperature measure
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
8# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
9tmp117 = TMP117(i2c)
10
11# uncomment different options below to see how it affects the reported temperature
12# and measurement time
13
14# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
15# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
16# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
17# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
18
19print(
20 "Number of averaged samples per measurement:",
21 AverageCount.string[tmp117.averaged_measurements],
22)
23print(
24 "Reads should take approximately",
25 AverageCount.string[tmp117.averaged_measurements] * 0.0155,
26 "seconds",
27)
28
29while True:
30 print("Single measurement: %.2f degrees C" % tmp117.take_single_measurement())
31 # time.sleep(1)