API Reference
adafruit_tmp117
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: https://github.com/sparkfunX/Qwiic_TMP117 https://github.com/sparkfun/SparkFun_TMP117_Arduino_Library
Serial number register information: https://e2e.ti.com/support/sensors/f/1023/t/815716?TMP117-Reading-Serial-Number-from-EEPROM
Implementation Notes
Hardware:
Adafruit TMP117 ±0.1°C High Accuracy I2C Temperature Sensor (Product ID: 4821)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- class adafruit_tmp117.AlertMode
Options for
alert_mode. Seealert_modefor more information.
- class adafruit_tmp117.AlertStatus(high_alert, low_alert)
Create new instance of AlertStatus(high_alert, low_alert)
- high_alert
Alias for field number 0
- 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. Seemeasurement_modefor more information.
- class adafruit_tmp117.TMP117(i2c_bus: busio.I2C, address: int = 72)
Library for the TI TMP117 high-accuracy temperature sensor
Create a driver for a TMP117 or TMP119 on the given I2C bus.
- Parameters:
- Raises:
AttributeError – if no TMP117/TMP119-family device answers at
address.
Note
The device-ID register reports a 16-bit value whose upper nibble is a silicon-revision field, not a part number: TMP117 =
0x0117, TMP119 =0x2117, both sharing DID[11:0] =0x117. The check below matches that shared field so future silicon revisions are still accepted.- property alert_mode: int
Sets the behavior of the
low_limit,high_limit, andalert_statusproperties.When set to
AlertMode.WINDOW, thehigh_limitproperty will unset when the measured temperature goes belowhigh_limit. Similarlylow_limitwill be True or False depending on if the measured temperature is below (False) or above(True)low_limit.When set to
AlertMode.HYSTERESIS, thehigh_limitproperty will be set toFalsewhen the measured temperature goes belowlow_limit. In this mode, thelow_limitproperty ofalert_statuswill not be set.The default is
AlertMode.WINDOW
- property alert_status: AlertStatus
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.
- Returns:
an
AlertStatusnamedtuple(high_alert, low_alert)of booleans.- Return type:
Warning
Reading this property reads the configuration register, which clears the latched HIGH/LOW alert flags in window mode (
AlertMode.WINDOW). Read it once per loop and reuse the result; reading it twice can miss an alert that the first read cleared. In hysteresis mode (AlertMode.HYSTERESIS) the flag is not cleared by a register read.Note
In hysteresis mode
low_alertis alwaysFalse(the low flag is disabled); onlyhigh_alertis meaningful.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]) print("") print("") 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) print("") time.sleep(1)
- 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_delayNote 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- Returns:
the current
AverageCountregister code (number of averaged samples).- Return type:
- property high_limit: float
The high temperature limit in degrees Celsius. When the measured temperature exceeds this value, the
high_alertattribute of thealert_statusproperty will be True. See the documentation foralert_statusfor more information.- Returns:
the high limit in degrees Celsius.
- Return type:
- initialize() None
Configure the sensor with sensible defaults.
initializeis primarily provided to be called afterreset, however it can also be used to easily set the sensor to a known configuration- Returns:
None- Return type:
None
- property low_limit: float
The low temperature limit in degrees Celsius. When the measured temperature goes below this value, the
low_alertattribute of thealert_statusproperty will be True. See the documentation foralert_statusfor more information.- Returns:
the low limit in degrees Celsius.
- Return type:
- 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 offaveraged_measurementswhich determines the minimum time needed between reported measurements.- Returns:
the current
MeasurementDelayregister code.- Return type:
- property measurement_mode
- Sets the measurement mode, specifying the behavior of how often measurements are taken.
measurement_modemust be one of:
Mode
Behavior
MeasurementMode.CONTINUOUSMeasurements are made at the interval determined by
averaged_measurementsandmeasurement_delay.temperaturereturns the most recent measurementMeasurementMode.ONE_SHOTTake a single measurement with the current number of
averaged_measurementsand switch toSHUTDOWNwhenfinished.
temperaturewill return the new measurement untilmeasurement_modeis set toCONTINUOUSorONE_SHOTisset again.
MeasurementMode.SHUTDOWNThe sensor is put into a low power state and no new
measurements are taken.
temperaturewill return the last measurement untila new
measurement_modeis selected.- Returns:
the current
MeasurementModeregister code.- Return type:
- property serial_number: int
A 48-bit, factory-set unique identifier for the device.
- Returns:
the 48-bit unique ID from EEPROM as an integer.
- Return type:
Note
This reads the factory NIST-traceability ID stored in EEPROM1-3. It is only meaningful if those EEPROM locations have not been reprogrammed for general-purpose use.
- take_single_measurement() float
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 untiltake_single_measurement()ortemperatureare read.- Returns:
the freshly measured temperature in degrees Celsius.
- Return type:
Note: if
averaged_measurementsis 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: float
The current measured temperature in degrees Celsius.
- Returns:
the most recent temperature in degrees Celsius.
- Return type:
Note
In continuous-conversion mode this returns the most recent sample and does not block. After a
resetand before the first conversion completes, the sensor reports -256 degrees C.
- property temperature_offset: float
User defined temperature offset to be added to measurements from
temperature.The offset is applied inside the sensor (added after linearization) and is in the same -256 to +255.9921 degrees C range as the temperature result.
- Returns:
the configured offset in degrees Celsius.
- Return type: