Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_tmp117 import tmp117
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2
tmp = tmp117.TMP117(i2c)
while True:
print(f"Temperature: {tmp.temperature:.2f}°C")
print("----------")
time.sleep(1)
Temperature Offset¶
Example to show the temperature offset
import time
from machine import Pin, I2C
from micropython_tmp117 import tmp117
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2
tmp = tmp117.TMP117(i2c)
print("Temperature without offset: ", tmp.temperature)
tmp.temperature_offset = 10.0
while True:
print(f"Temperature offset: {tmp.temperature:.2f}°C")
print()
time.sleep(1)
Temperature Alert Mode¶
Example illustrating the Alert mode functionality
import time
from machine import Pin, I2C
from micropython_tmp117 import tmp117
i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2
tmp = tmp117.TMP117(i2c)
tmp.high_limit = 23
tmp.low_limit = 20
print("Alert mode:", tmp.alert_mode)
print("High limit", tmp.high_limit)
print("Low limit", tmp.low_limit)
while True:
print(f"Alert status: {tmp.alert_status:.2f}°C")
alert_status = tmp.alert_status
if alert_status.high_alert:
print("Temperature above high set limit!")
if alert_status.low_alert:
print("Temperature below low set limit!")
print("Low alert:", alert_status.low_alert)
time.sleep(1)
Temperature Averaging Setting¶
Example illustrating the Averaging measurement setting
# SPDX-License-Identifier: MIT
import time
from machine import Pin, I2C
from micropython_tmp117 import tmp117
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
tmp = tmp117.TMP117(i2c)
tmp.averaging_measurements = tmp117.AVERAGE_64X
while True:
for averaging_measurements in tmp117.averaging_measurements_values:
print("Current Averaging measurements setting: ", tmp.averaging_measurements)
for _ in range(10):
print(f"Temperature: {tmp.temperature:.2f}°C")
print()
time.sleep(0.5)
tmp.averaging_measurements = averaging_measurements