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
 5
 6import board
 7
 8import adafruit_tmp117
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12tmp117 = adafruit_tmp117.TMP117(i2c)
13
14while True:
15    print(f"Temperature: {tmp117.temperature:.2f} degrees C")
16    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
 5
 6import board
 7
 8from adafruit_tmp117 import TMP117, AlertMode
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12
13tmp117 = TMP117(i2c)
14
15tmp117.high_limit = 25
16tmp117.low_limit = 10
17
18print("\nHigh limit", tmp117.high_limit)
19print("Low limit", tmp117.low_limit)
20
21# Try changing `alert_mode`  to see how it modifies the behavior of the alerts.
22# tmp117.alert_mode = AlertMode.WINDOW #default
23# tmp117.alert_mode = AlertMode.HYSTERESIS
24
25print("Alert mode:", AlertMode.string[tmp117.alert_mode])
26print("\n\n")
27while True:
28    print(f"Temperature: {tmp117.temperature:.2f} degrees C")
29    alert_status = tmp117.alert_status
30    print("High alert:", alert_status.high_alert)
31    print("Low alert:", alert_status.low_alert)
32    print("")
33    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
 9
10import board
11
12from adafruit_tmp117 import TMP117, AverageCount, MeasurementDelay
13
14i2c = board.I2C()  # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16tmp117 = TMP117(i2c)
17
18# uncomment different options below to see how it affects the reported temperature
19# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
20# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
21# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
22# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
23
24# tmp117.measurement_delay = MeasurementDelay.DELAY_0_0015_S
25# tmp117.measurement_delay = MeasurementDelay.DELAY_0_125_S
26# tmp117.measurement_delay = MeasurementDelay.DELAY_0_250_S
27# tmp117.measurement_delay = MeasurementDelay.DELAY_0_500_S
28# tmp117.measurement_delay = MeasurementDelay.DELAY_1_S
29# tmp117.measurement_delay = MeasurementDelay.DELAY_4_S
30# tmp117.measurement_delay = MeasurementDelay.DELAY_8_S
31# tmp117.measurement_delay = MeasurementDelay.DELAY_16_S
32
33print(
34    "Number of averaged samples per measurement:",
35    AverageCount.string[tmp117.averaged_measurements],
36)
37print(
38    "Minimum time between measurements:",
39    MeasurementDelay.string[tmp117.measurement_delay],
40    "seconds",
41)
42print("")
43
44while True:
45    print("Temperature:", tmp117.temperature)
46    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
 5
 6import board
 7
 8import adafruit_tmp117
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12
13tmp117 = adafruit_tmp117.TMP117(i2c)
14
15print(f"Temperature without offset: {tmp117.temperature:.2f} degrees C")
16tmp117.temperature_offset = 10.0
17while True:
18    print(f"Temperature w/ offset: {tmp117.temperature:.2f} degrees C")
19    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
 5
 6from adafruit_tmp117 import TMP117, AverageCount
 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 = TMP117(i2c)
11
12# uncomment different options below to see how it affects the reported temperature
13# and measurement time
14
15# tmp117.averaged_measurements = AverageCount.AVERAGE_1X
16# tmp117.averaged_measurements = AverageCount.AVERAGE_8X
17# tmp117.averaged_measurements = AverageCount.AVERAGE_32X
18# tmp117.averaged_measurements = AverageCount.AVERAGE_64X
19
20print(
21    "Number of averaged samples per measurement:",
22    AverageCount.string[tmp117.averaged_measurements],
23)
24print(
25    "Reads should take approximately",
26    AverageCount.string[tmp117.averaged_measurements] * 0.0155,
27    "seconds",
28)
29
30while True:
31    print(f"Single measurement: {tmp117.take_single_measurement():.2f} degrees C")
32    # time.sleep(1)

DisplayIO Simpletest

This is a simple test for boards with built-in display.

examples/tmp117_displayio_simpletest.py
 1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
 2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
 3#
 4# SPDX-License-Identifier: MIT
 5
 6import time
 7
 8import board
 9from adafruit_display_text.bitmap_label import Label
10from displayio import Group
11from terminalio import FONT
12
13import adafruit_tmp117
14
15# Simple demo of using the built-in display.
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C()  # uses board.SCL and board.SDA
20tmp117 = adafruit_tmp117.TMP117(i2c)
21
22# Create Label(s) to show the readings. If you have a very small
23# display you may need to change to scale=1.
24display_output_label = Label(FONT, text="", scale=2)
25
26# place the label(s) in the middle of the screen with anchored positioning
27display_output_label.anchor_point = (0, 0)
28display_output_label.anchored_position = (
29    4,
30    board.DISPLAY.height // 2 - 60,
31)
32
33# add the label(s) to the main_group
34main_group.append(display_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41    # update the text of the label(s) to show the sensor readings
42    display_output_label.text = f"Temperature: {tmp117.temperature:.1f} C"
43    # wait for a bit
44    time.sleep(0.5)