You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
24
12
13
+
This repository implements a Python package for the SparkFun Qwiic TMP102. This package works with Python, MicroPython and CircuitPython.
25
14
26
-
Python module for the [SparkFun Qwiic TMP102 Sensor](https://www.sparkfun.com/products/16304)
15
+
### Contents
27
16
28
-
This python package is a port of the existing [SparkFun TMP102 Arduino Examples](https://github.com/sparkfun/SparkFun_TMP102_Arduino_Library/tree/master/examples)
This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py)
24
+
## About the Package
25
+
26
+
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.
31
27
32
28
New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic).
33
29
34
-
##Contents
30
+
### Supported SparkFun Products
35
31
36
-
*[Supported Platforms](#supported-platforms)
37
-
*[Dependencies](#dependencies)
38
-
*[Installation](#installation)
39
-
*[Documentation](#documentation)
40
-
*[Example Use](#example-use)
32
+
This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python.
33
+
34
+
*[SparkFun Digital Temperature Sensing Sensor - TMP102](https://www.sparkfun.com/products/16304)
35
+
36
+
### Supported Platforms
37
+
38
+
| Python | Platform | Boards |
39
+
|--|--|--|
40
+
| Python | Linux |[Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html)|
> 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.
46
+
47
+
## Installation
48
+
49
+
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.
50
+
51
+
### Python
41
52
42
-
Supported Platforms
43
-
--------------------
44
-
The qwiic TMP102 Python package current supports the following platforms:
The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi".
53
56
54
-
Documentation
55
-
-------------
56
-
The SparkFun qwiic TMP102 module documentation is hosted at [ReadTheDocs](https://qwiic-tmp102-py.readthedocs.io/en/latest/?)
57
+
Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system.
57
58
58
-
Installation
59
-
---------------
60
-
### PyPi Installation
59
+
First, setup a virtual environment from a specific directory using venv:
60
+
```sh
61
+
python3 -m venv path/to/venv
62
+
```
63
+
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](https://docs.python.org/3/library/venv.html).
Now you should be able to run any example or custom python scripts that have `import qwiic_tmp102` by running e.g.:
70
+
```sh
71
+
path/to/venv/bin/python3 example_script.py
72
+
```
61
73
62
-
This repository is hosted on PyPi as the [sparkfun-qwiic-tmp102](https://pypi.org/project/sparkfun-qwiic-tmp102/) package. On systems that support PyPi installation via pip, this library is installed using the following commands
74
+
### MicroPython Installation
75
+
If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer.
63
76
64
-
For all users (note: the user must have sudo privileges):
77
+
Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.
To install, make sure the setuptools package is installed on the system.
74
86
75
-
Direct installation at the command line:
87
+
### CircuitPython Installation
88
+
If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer.
89
+
90
+
Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.
76
91
```sh
77
-
python setup.py install
92
+
circup bundle-add sparkfun/Qwiic_Py
78
93
```
79
94
80
-
To build a package for use with pip:
95
+
Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.
81
96
```sh
82
-
python setup.py sdist
83
-
```
84
-
A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.
97
+
circup install --py qwiic_tmp102
98
+
```
99
+
100
+
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 [CircUp "example" command documentation](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command) for more information)
circup example qwiic_tmp102\Example1-GetTemperature
104
+
circup example qwiic_tmp102\Example2_One-Shot_Temperature_Reading
105
+
88
106
```
89
107
90
108
Example Use
91
-
-------------
92
-
See the examples directory for more detailed use examples.
109
+
---------------
110
+
Below is a quickstart program to print readings from the TMP102.
111
+
112
+
See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_tmp102_py/blob/main/examples/README.md) for a summary of the available examples.
93
113
94
114
```python
95
-
from__future__import print_function
115
+
96
116
import qwiic_tmp102
97
117
import time
98
118
import sys
99
119
100
120
defrunExample():
101
121
102
-
print("\nSparkFun Qwiic TMP102 Sensor Test Example\n")
122
+
print("\nSparkFun Qwiic TMP102 Sensor Example 1\n")
103
123
myTmpSensor = qwiic_tmp102.QwiicTmp102Sensor()
104
124
105
125
if myTmpSensor.is_connected ==False:
@@ -111,10 +131,34 @@ def runExample():
111
131
112
132
print("Initialized.")
113
133
134
+
135
+
myTmpSensor.set_fault(0)
136
+
137
+
myTmpSensor.set_alert_polarity(1) # Active HIGH
138
+
139
+
myTmpSensor.set_alert_mode(0) # Comparator Mode.
140
+
141
+
myTmpSensor.set_conversion_rate(2)
142
+
143
+
myTmpSensor.set_extended_mode(0)
144
+
145
+
myTmpSensor.set_high_temp_f(85.0) # set T_HIGH in F
Below is a brief summary of each of the example programs included in this repository. To report a bug in any of these examples or to request a new feature or example [submit an issue in our GitHub issues.](https://github.com/sparkfun/qwiic_tmp102_py/issues).
3
+
4
+
NOTE: Any numbering of examples is to retain consistency with the Arduino library from which this was ported.
5
+
6
+
## Example1-Gettemperature
7
+
Simple Example for the Qwiic TMP102 Device
8
+
9
+
## Example2 One-Shot Temperature Reading
10
+
This sketch connects to the TMP102 temperature sensor and enables the
11
+
one-shot temperature measurement mode using the one_shot() function.
12
+
The function returns 0 until the temperature measurement is ready to
13
+
read (takes around 25ms). After the measurment is read, the TMP102 is
14
+
placed back into sleep mode before the loop is repeated. This can be
15
+
useful to save power or increase the continuous conversion rate from
16
+
8Hz up to a maximum of 40Hz.
17
+
18
+
This code is beerware; if you see me (or any other SparkFun employee) at
19
+
the local, and you've found our code helpful, please buy us a round!
0 commit comments