Skip to content

Documentation changes #7

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 13, 2021
Merged
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
39 changes: 34 additions & 5 deletions adafruit_shtc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
`adafruit_shtc3`
================================================================================

A helper library for using the Senserion SHTC3 Humidity and Temperature Sensor
A helper library for using the Sensirion SHTC3 Humidity and Temperature Sensor


* Author(s): Bryan Siepert
Expand All @@ -16,7 +16,7 @@

**Hardware:**

* Adafruit's ICM20649 Breakout: https://www.adafruit.com/product/4636
* Adafruit's SHTC3 Temperature & Humidity Sensor: https://www.adafruit.com/product/4636

**Software and Dependencies:**

Expand Down Expand Up @@ -83,6 +83,32 @@ class SHTC3:

:param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.

**Quickstart: Importing and using the SHTC3 temperature and humidity sensor**

Here is one way of importing the `SHTC3` class so you can use it with the name ``sht``.
First you will need to import the helper libraries to use the sensor

.. code-block:: python

import busio
import board
import adafruit_shtc3

Once this is done, you can define your `busio.I2C` object and define your sensor

.. code-block:: python

i2c = busio.I2C(board.SCL, board.SDA)
sht = adafruit_shtc3.SHTC3(i2c)

Now you have access to the temperature and humidity using the :attr:`measurements`.
it will return a tuple with the :attr:`temperature` and :attr:`relative_humidity`
measurements

.. code-block:: python

temperature, relative_humidity = sht.measurements

"""

def __init__(self, i2c_bus):
Expand All @@ -93,9 +119,10 @@ def __init__(self, i2c_bus):
self.sleeping = False
self.reset()
if self._chip_id & 0x083F != _SHTC3_CHIP_ID:
raise RuntimeError("Failed to find an ICM20X sensor - check your wiring!")
raise RuntimeError("Failed to find an SHTC3 sensor - check your wiring!")

def _write_command(self, command):
"""helper function to write a command to the i2c device"""
self._buffer[0] = command >> 8
self._buffer[1] = command & 0xFF

Expand All @@ -104,6 +131,7 @@ def _write_command(self, command):

@property
def _chip_id(self): # readCommand(SHTC3_READID, data, 3);
"""Determines the chip id of the sensor"""
self._buffer[0] = _SHTC3_READID >> 8
self._buffer[1] = _SHTC3_READID & 0xFF

Expand Down Expand Up @@ -152,12 +180,12 @@ def low_power(self, low_power_enabled):

@property
def relative_humidity(self):
"""The current relative humidity in % rH"""
"""The current relative humidity in % rH. This is a value from 0-100%."""
return self.measurements[1]

@property
def temperature(self):
"""The current temperature in degrees celcius"""
"""The current temperature in degrees Celsius"""
return self.measurements[0]

@property
Expand Down Expand Up @@ -213,6 +241,7 @@ def measurements(self):

@staticmethod
def _crc8(buffer):
"""verify the crc8 checksum"""
crc = 0xFF
for byte in buffer:
crc ^= byte
Expand Down