MicroPython TMP117 Library¶
tmp117¶
MicroPython Driver for the TMP117 temperature sensor
Author(s): Jose D. Montoya
Implementation Notes¶
Software and Dependencies:
This library depends on Micropython
- class micropython_tmp117.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 micropython_tmp117.tmp117.TMP117(i2c, address=
0x48)[source]¶ Main class for the Sensor
- Parameters:¶
- Raises:¶
RuntimeError – if the sensor is not found
Quickstart: Importing and using the device
Here is an example of using the
TMP117class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C import micropython_tmp117 import tmp117Once this is done you can define your
machine.I2Cobject and define your sensor objecti2c = I2C(sda=Pin(8), scl=Pin(9)) tmp117 = tmp117.TMP117(i2c)Now you have access to the
temperatureattributetemp = tmp117.temperature- property alert_mode : str¶
Sets the behavior of the
low_limit,high_limit, andalert_statusproperties.When set to
ALERT_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
ALERT_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
ALERT_WINDOWMode
Value
tmp117.ALERT_WINDOW0b0tmp117.ALERT_HYSTERESIS0b1
- 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.
from machine import Pin, I2C import micropython_tmp117.tmp117 as tmp117 i2c = I2C(sda=Pin(8), scl=Pin(9)) # Correct I2C pins for UM FeatherS2 tmp = tmp117.TMP117(i2c) tmp.low_limit = 20 tmp.high_limit = 23 print("Alert mode:", tmp.alert_mode) print("High limit", tmp.high_limit) print("Low limit", tmp.low_limit) while True: print("Temperature: %.2f degrees C" % tmp.temperature) 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)
- property averaging_measurements : str¶
Users can configure the device to report the average of multiple temperature conversions with the AVG[1:0] bits to reduce noise in the conversion results. When the TMP117 is configured to perform averaging with AVG set to 01, the device executes the configured number of conversions to eight. The device accumulates those conversion results and reports the average of all the collected results at the end of the process.
Mode
Value
tmp117.AVERAGE_1X0b00tmp117.AVERAGE_8X0b01tmp117.AVERAGE_32X0b10tmp117.AVERAGE_64X0b11
- property high_limit : float¶
The high temperature limit in Celsius. When the measured temperature exceeds this value, the
high_alertattribute of thealert_statusproperty will be True.
- property low_limit : float¶
The low temperature limit in Celsius. When the measured temperature goes below this value, the
low_alertattribute of thealert_statusproperty will be True.
- property measurement_mode : str¶
- Sets the measurement mode, specifying the behavior of how often measurements are taken.
measurement_modemust be one of:
When we use the sensor in One shot mode, the sensor will take the average_measurement value into account. However, this measure is done with the formula (15.5 ms x average_time), so in normal operation average_time will be 8, therefore time for measure is 124 ms. (See datasheet. 7.3.2 Averaging for more information). If we use 64, time will be 15.5 x 65 = 992 ms, the standby time will decrease, but the measure is still under 1 Hz cycle. (See Fig 7.2 on the datasheet)
Mode
Behavior
tmp117.CONTINUOUS_CONVERSION_MODEMeasurements are made at the interval determined by
averaging_measurements.temperaturereturns the most recent measurementtmp117.SHUTDOWN_MODETake a single measurement with the current number of
averaging_measurementsand switch toSHUTDOWNwhen finished.temperaturewill return the new measurement untilmeasurement_modeis set toCONTINUOUSorONE_SHOTis set again.tmp117.ONE_SHOT_MODEThe sensor is put into a low power state and no new measurements are taken.
temperaturewill return the last measurement until a newmeasurement_modeis selected.
- property temperature_offset : float¶
User defined temperature offset to be added to measurements from
temperature. In order the see the new change in the temperature we need for the data to be ready. There is a time delay calculated according to current configuration.