CircuitPython library for the TI TMP117 Temperature sensor

  • Author(s): Bryan Siepert, Ian Grant

parts based on SparkFun_TMP117_Arduino_Library by Madison Chodikov @ SparkFun Electronics:

Serial number register information:

Implementation Notes


Software and Dependencies:

class adafruit_tmp117.AlertMode

Options for alert_mode. See alert_mode for more information.

class adafruit_tmp117.AlertStatus(high_alert, low_alert)

Create new instance of AlertStatus(high_alert, low_alert)

property high_alert

Alias for field number 0

property low_alert

Alias for field number 1

class adafruit_tmp117.AverageCount

Options for averaged_measurements

class adafruit_tmp117.MeasurementDelay

Options for measurement_delay

class adafruit_tmp117.MeasurementMode

Options for measurement_mode. See measurement_mode for more information.

class adafruit_tmp117.TMP117(i2c_bus, address=72)

Library for the TI TMP117 high-accuracy temperature sensor

property alert_mode

Sets the behavior of the low_limit, high_limit, and alert_status properties.

When set to AlertMode.WINDOW, the high_limit property will unset when the measured temperature goes below high_limit. Similarly low_limit will be True or False depending on if the measured temperature is below (False) or above(True) low_limit.

When set to AlertMode.HYSTERESIS, the high_limit property will be set to False when the measured temperature goes below low_limit. In this mode, the low_limit property of alert_status will not be set.

The default is AlertMode.WINDOW

property alert_status

The current triggered status of the high and low temperature alerts as a AlertStatus named tuple with attributes for the triggered status of each alert.

import board
import adafruit_tmp117
i2c = board.I2C()  # uses board.SCL and board.SDA

tmp117 = adafruit_tmp117.TMP117(i2c)

tmp117.high_limit = 25
tmp117.low_limit = 10

print("High limit", tmp117.high_limit)
print("Low limit", tmp117.low_limit)

# Try changing `alert_mode`  to see how it modifies the behavior of the alerts.
# tmp117.alert_mode = AlertMode.WINDOW #default
# tmp117.alert_mode = AlertMode.HYSTERESIS

print("Alert mode:", AlertMode.string[tmp117.alert_mode])
while True:
    print("Temperature: %.2f degrees C" % tmp117.temperature)
    alert_status = tmp117.alert_status
    print("High alert:", alert_status.high_alert)
    print("Low alert:", alert_status.low_alert)
property averaged_measurements

The number of measurements that are taken and averaged before updating the temperature measurement register. A larger number will reduce measurement noise but may also affect the rate at which measurements are updated, depending on the value of measurement_delay

Note that each averaged measurement takes 15.5ms which means that larger numbers of averaged measurements may make the delay between new reported measurements to exceed the delay set by measurement_delay

property high_limit

The high temperature limit in degrees Celsius. When the measured temperature exceeds this value, the high_alert attribute of the alert_status property will be True. See the documentation for alert_status for more information


Configure the sensor with sensible defaults. initialize is primarily provided to be called after reset, however it can also be used to easily set the sensor to a known configuration

property low_limit

The low temperature limit in degrees Celsius. When the measured temperature goes below this value, the low_alert attribute of the alert_status property will be True. See the documentation for alert_status for more information

property measurement_delay

The minimum amount of time between measurements in seconds. Must be a MeasurementDelay. The specified amount may be exceeded depending on the current setting off averaged_measurements which determines the minimum time needed between reported measurements.

property measurement_mode
Sets the measurement mode, specifying the behavior of how often measurements are taken.

measurement_mode must be one of:




Measurements are made at the interval determined by

averaged_measurements and measurement_delay.

temperature returns the most recent measurement


Take a single measurement with the current number of

averaged_measurements and switch to SHUTDOWN when


temperature will return the new measurement until

measurement_mode is set to CONTINUOUS or ONE_SHOT is

set again.


The sensor is put into a low power state and no new

measurements are taken.

temperature will return the last measurement until

a new measurement_mode is selected.


Reset the sensor to its unconfigured power-on state

property serial_number

A 48-bit, factory-set unique identifier for the device.


Perform a single measurement cycle respecting the value of averaged_measurements, returning the measurement once complete. Once finished the sensor is placed into a low power state until take_single_measurement() or temperature are read.

Note: if averaged_measurements is set to a high value there will be a notable delay before the temperature measurement is returned while the sensor takes the required number of measurements

property temperature

The current measured temperature in degrees Celsius

property temperature_offset

User defined temperature offset to be added to measurements from temperature