Skip to content

-Improving docs #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 34 additions & 7 deletions adafruit_sht31d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

**Hardware:**

* Adafruit `Sensiron SHT31-D Temperature & Humidity Sensor Breakout
<https://www.adafruit.com/product/2857>`_ (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
"""

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit Sensirion SHT31-D Temperature & Humidity Sensor Breakout <https://learn.adafruit.com/adafruit-sht31-d-temperature-and-humidity-sensor-breakout>

.. toctree::
:caption: Related Products

Adafruit Sensiron SHT31-D Temperature & Humidity Sensor Breakout <https://www.adafruit.com/product/2857>
Adafruit Sensirion SHT31-D Temperature & Humidity Sensor Breakout <https://www.adafruit.com/product/2857>

.. toctree::
:caption: Other Links
Expand Down
6 changes: 2 additions & 4 deletions examples/sht31d_periodic_mode.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
5 changes: 2 additions & 3 deletions examples/sht31d_simple_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions examples/sht31d_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down