diff --git a/README.rst b/README.rst index 9b357dc..304dce4 100644 --- a/README.rst +++ b/README.rst @@ -63,15 +63,13 @@ You must import the library to use it: This driver takes an instantiated and active I2C object (from the `busio` or the `bitbangio` library) as an argument to its constructor. The way to create -an I2C object depends on the board you are using. For boards with labeled SCL -and SDA pins, you can: +an I2C object depends on the board you are using. .. code:: python - from busio import I2C - from board import SCL, SDA + from board - i2c = I2C(SCL, SDA) + i2c = board.I2C() Once you have created the I2C interface object, you can use it to instantiate the sensor object: diff --git a/adafruit_sht31d.py b/adafruit_sht31d.py index b572cd8..362707e 100644 --- a/adafruit_sht31d.py +++ b/adafruit_sht31d.py @@ -16,13 +16,13 @@ **Hardware:** -* Adafruit `Sensiron SHT31-D Temperature & Humidity Sensor Breakout - `_ (Product ID: 2857) +* Adafruit SHT31-D temperature and humidity sensor Breakout: https://www.adafruit.com/product/2857 **Software and Dependencies:** -* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: - https://github.com/adafruit/circuitpython/releases +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ @@ -145,8 +145,35 @@ class SHT31D: """ A driver for the SHT31-D temperature and humidity sensor. - :param i2c_bus: The `busio.I2C` object to use. This is the only required parameter. - :param int address: (optional) The I2C address of the device. + :param ~busio.I2C i2c_bus: The I2C bus the SHT31-D is connected to + :param int address: (optional) The I2C address of the device. Defaults to :const:`0x44` + + **Quickstart: Importing and using the SHT31-D** + + Here is an example of using the :class:`SHT31D` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_sht31d + + Once this is done you can define your `board.I2C` object and define your sensor object + + .. code-block:: python + + i2c = board.I2C() # uses board.SCL and board.SDA + sht = adafruit_sht31d.SHT31D(i2c) + + Now you have access to the temperature and humidity the + the :attr:`temperature` and :attr:`relative_humidity` attributes + + + .. code-block:: python + + temperature = sht.temperature + humidity = sht.relative_humidity + """ def __init__(self, i2c_bus, address=_SHT31_DEFAULT_ADDRESS): @@ -326,7 +353,7 @@ def frequency(self, value): @property def temperature(self): """ - The measured temperature in degrees celsius. + The measured temperature in degrees Celsius. 'Single' mode reads and returns the current temperature as a float. 'Periodic' mode returns the most recent readings available from the sensor's cache in a FILO list of eight floats. This list is backfilled with with the diff --git a/docs/examples.rst b/docs/examples.rst index 64cd1d7..048eead 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,21 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/sht31d_simpletest.py :caption: examples/sht31d_simpletest.py :linenos: + +Simple Mode +------------ + +Example in how to use the sensor in simple mode + +.. literalinclude:: ../examples/sht31d_simple_mode.py + :caption: examples/sht31d_simple_mode.py + :linenos: + +Periodic Mode +------------- + +Example in how to use the sensor in periodic mode + +.. literalinclude:: ../examples/sht31d_simpletest.py + :caption: examples/sht31d_simpletest.py + :linenos: diff --git a/docs/index.rst b/docs/index.rst index a0c659b..6d88f1e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,10 +23,12 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit Sensirion SHT31-D Temperature & Humidity Sensor Breakout + .. toctree:: :caption: Related Products - Adafruit Sensiron SHT31-D Temperature & Humidity Sensor Breakout + Adafruit Sensirion SHT31-D Temperature & Humidity Sensor Breakout .. toctree:: :caption: Other Links diff --git a/examples/sht31d_periodic_mode.py b/examples/sht31d_periodic_mode.py index 28ba7cc..3c58977 100644 --- a/examples/sht31d_periodic_mode.py +++ b/examples/sht31d_periodic_mode.py @@ -1,14 +1,12 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -#!/usr/bin/python3 import time import board -import busio import adafruit_sht31d -# Create library object using our Bus I2C port -i2c = busio.I2C(board.SCL, board.SDA) +# Create sensor object, communicating over the board's default I2C bus +i2c = board.I2C() sensor = adafruit_sht31d.SHT31D(i2c) print("\033[1mSensor\033[0m = SHT31-D") diff --git a/examples/sht31d_simple_mode.py b/examples/sht31d_simple_mode.py index d1d99c5..400373b 100644 --- a/examples/sht31d_simple_mode.py +++ b/examples/sht31d_simple_mode.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: MIT import board -import busio import adafruit_sht31d -# Create library object using our Bus I2C port -i2c = busio.I2C(board.SCL, board.SDA) +# Create sensor object, communicating over the board's default I2C bus +i2c = board.I2C() sensor = adafruit_sht31d.SHT31D(i2c) print("\033[1mSensor\033[0m = SHT31-D") diff --git a/examples/sht31d_simpletest.py b/examples/sht31d_simpletest.py index 844f346..e969b63 100644 --- a/examples/sht31d_simpletest.py +++ b/examples/sht31d_simpletest.py @@ -3,11 +3,10 @@ import time import board -import busio import adafruit_sht31d -# Create library object using our Bus I2C port -i2c = busio.I2C(board.SCL, board.SDA) +# Create sensor object, communicating over the board's default I2C bus +i2c = board.I2C() sensor = adafruit_sht31d.SHT31D(i2c) loopcount = 0