Simple test
Ensure your device works with this simple test.
examples/tmp117_simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | # SPDX-FileCopyrightText: 2023 Jose D. Montoya
#
# SPDX-License-Identifier: Unlicense
import time
import board
import tmp117
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
tmp = tmp117.TMP117(i2c)
while True:
print(f"Temperature: {tmp.temperature:.2f}°C")
print()
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 | # SPDX-FileCopyrightText: 2023 Jose D. Montoya
#
# SPDX-License-Identifier: Unlicense
import time
import board
import tmp117
i2c = board.I2C() # uses board.SCL and board.SDA
tmp = tmp117.TMP117(i2c)
tmp.high_limit = 25
tmp.low_limit = 10
print("\nHigh limit", tmp.high_limit)
print("Low limit", tmp.low_limit)
# Try changing `alert_mode` to see how it modifies the behavior of the alerts.
# tmp117.alert_mode = adafruit_tmp117.ALERT_WINDOW #default
# tmp117.alert_mode = adafruit_tmp117.ALERT_HYSTERESIS
print("Alert mode:", tmp117.alert_mode)
print("\n\n")
while True:
print(f"Temperature: {tmp.temperature:.2f}°C")
print()
alert_status = tmp117.alert_status
print("High alert:", alert_status.high_alert)
print("Low alert:", alert_status.low_alert)
print("")
time.sleep(1)
|
Measurement delay settings
Example showing the Measurement delay setting
examples/tmp117_measurement_delay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import tmp117
i2c = board.I2C()
tmp = tmp117.TMP117(i2c)
tmp.measurement_delay = tmp117.DELAY_8_S
delay_times = {
0: "DELAY_0_0015_S",
1: "DELAY_0_125_S",
2: "DELAY_0_250_S",
3: "DELAY_0_500_S",
4: "DELAY_1_S",
5: "DELAY_4_S",
6: "DELAY_8_S",
7: "DELAY_16_S",
}
while True:
for measurement_delay in range(8):
print("Current Measurement delay setting: ", delay_times[tmp.measurement_delay])
for _ in range(10):
print(f"Temperature: {tmp.temperature:.2f}°C")
print()
time.sleep(0.5)
tmp.measurement_delay = measurement_delay
|
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | # SPDX-FileCopyrightText: 2023 Jose D. Montoya
#
# SPDX-License-Identifier: Unlicense
import time
import board
import tmp117
# i2c = board.I2C() # uses board.SCL and board.SDA
i2c = (
board.STEMMA_I2C()
) # For using the built-in STEMMA QT connector on a microcontroller
tmp = tmp117.TMP117(i2c)
print("Temperature without offset: ", tmp.temperature)
tmp117.temperature_offset = 10.0
while True:
print(f"Temperature with offset: {tmp.temperature:.2f}°C")
print()
time.sleep(1)
|
Averaged measurements settings
Example showing the Averaged measurements setting
examples/tmp117_averaged_measurements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import tmp117
i2c = board.I2C()
tmp = tmp117.TMP117(i2c)
tmp.averaged_measurements = tmp117.AVERAGE_1X
while True:
for averaged_measurements in tmp117.averaged_measurements_values:
print("Current Averaged measurements setting: ", tmp.averaged_measurements)
for _ in range(10):
print(f"Temperature: {tmp.temperature:.2f}°C")
print()
time.sleep(0.5)
tmp.averaged_measurements = averaged_measurements
|