![]() |
Qwiic_TMP102_Py
packaging_test1-1-g6ea6532
Python for SFE Qwiic TMP102
|
The SparkFun Qwiic Digital Temperature Sensing TMP102 Module provides a simple and cost effective solution for adding Digital Temperature Sensing capabilities to your project. Implementing a SparkFun Qwiic I2C interface, these sensors can be rapidly added to any project with boards that are part of the SparkFun Qwiic ecosystem.
This repository implements a Python package for the SparkFun Qwiic TMP102. This package works with Python, MicroPython and CircuitPython.
This python package enables the user to access the features of the TMP102 via a single Qwiic cable. This includes <reading temperature, setting alerts> and more. The capabilities of the TMP102 are each demonstrated in the included examples.
New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.
This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python.
Python | Platform | Boards |
---|---|---|
Python | Linux | Raspberry Pi , NVIDIA Jetson Orin Nano via the SparkFun Qwiic SHIM |
MicroPython | Raspberry Pi - RP2, ESP32 | SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+ |
CircuitPython | Raspberry Pi - RP2, ESP32 | SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+ |
[!NOTE] The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems.
The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython.
The package is primarily installed using the pip3
command, downloading the package from the Python Index - "PyPi".
Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system.
First, setup a virtual environment from a specific directory using venv:
You can pass any path as path/to/venv, just make sure you use the same one for all future steps. For more information on venv click here.
Next, install the qwiic package with:
Now you should be able to run any example or custom python scripts that have import qwiic_tmp102
by running e.g.:
If not already installed, follow the instructions here to install mpremote on your computer.
Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.
If you would also like to install the examples for this repository, issue the following mip command as well:
If not already installed, follow the instructions here to install CircUp on your computer.
Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.
Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.
If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUp on Windows. Linux and Mac will have different path seperators (i.e. "/" vs. "\"). See the <a href="https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command" >CircUp \"example\" command documentation</a> for more information)
@icode{sh}
circup example qwiic_tmp102\Example1_GetTemperature
circup example qwiic_tmp102\Example2_One_Shot_Temperature_Reading
@endicode
@subsection autotoc_md11 Example Use
Below is a quickstart program to print readings from the TMP102.
See the examples directory for more detailed use examples and <a href="https://github.com/sparkfun/qwiic_tmp102_py/blob/main/examples/README.md" >examples/README.md</a> for a summary of the available examples.
@icode{python}
import qwiic_tmp102
import time
import sys
def runExample():
print("\nSparkFun Qwiic TMP102 Sensor Example 1
")
myTmpSensor = qwiic_tmp102.QwiicTmp102Sensor()
if myTmpSensor.is_connected == False:
print("The Qwiic TMP102 Sensor device isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
myTmpSensor.begin()
print("Initialized.")
myTmpSensor.set_fault(0)
myTmpSensor.set_alert_polarity(1) # Active HIGH
myTmpSensor.set_alert_mode(0) # Comparator Mode.
myTmpSensor.set_conversion_rate(2)
myTmpSensor.set_extended_mode(0)
myTmpSensor.set_high_temp_f(85.0) # set T_HIGH in F
myTmpSensor.set_low_temp_f(84.0) # set T_LOW in F
while True:
myTmpSensor.wakeup()
temperature = myTmpSensor.read_temp_f()
alertRegisterState = myTmpSensor.alert() # read the Alert from register
myTmpSensor.sleep()
print("Temperature: ", temperature)
print("Alert Register: ", alertRegisterState)
time.sleep(2)
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding Example 1")
sys.exit(0)
@endicode
<p align="center">
<img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something">