diff --git a/adafruit_ahtx0.py b/adafruit_ahtx0.py index cff1d87..dab8d45 100644 --- a/adafruit_ahtx0.py +++ b/adafruit_ahtx0.py @@ -6,7 +6,7 @@ `adafruit_ahtx0` ================================================================================ -CircuitPython driver for the Adafruit AHT10 Humidity and Temperature Sensor +CircuitPython driver for the Adafruit AHT10/AHT20 Temperature & Humidity Sensor * Author(s): Kattni Rembor @@ -16,7 +16,7 @@ **Hardware:** -* This is a library for the Adafruit AHT20 breakout: +* This is a library for the Adafruit AHT20 Temperature & Humidity Sensor breakout: https://www.adafruit.com/product/4566 **Software and Dependencies:** @@ -42,7 +42,39 @@ class AHTx0: - """Interface library for AHT10/AHT20 temperature+humidity sensors""" + """ + Interface library for AHT10/AHT20 temperature+humidity sensors + + :param ~busio.I2C i2c_bus: The I2C bus the AHT10/AHT20 is connected to. + :param address: The I2C device address for the sensor. Default is :const:`0x38` + + **Quickstart: Importing and using the AHT10/AHT20 temperature sensor** + + Here is one way of importing the `AHTx0` class so you can use it with the name ``aht``. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import busio + import board + import adafruit_ahtx0 + + Once this is done you can define your `busio.I2C` object and define your sensor object + + .. code-block:: python + + i2c = busio.I2C(board.SCL, board.SDA) + aht = adafruit_ahtx0.AHTx0(i2c) + + Now you have access to the temperature and humidity using + the :attr:`temperature` and :attr:`relative_humidity` attributes + + .. code-block:: python + + temperature = aht.temperature + relative_humidity = aht.relative_humidity + + """ def __init__(self, i2c_bus, address=AHTX0_I2CADDR_DEFAULT): time.sleep(0.02) # 20ms delay to wake up @@ -90,7 +122,7 @@ def relative_humidity(self): @property def temperature(self): - """The measured temperature in degrees Celcius.""" + """The measured temperature in degrees Celsius.""" self._readdata() return self._temp diff --git a/docs/index.rst b/docs/index.rst index 151d0e7..13c8720 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -26,7 +26,7 @@ Table of Contents .. toctree:: :caption: Related Products - https://www.adafruit.com/product/4566 + Adafruit AHT20 - Temperature & Humidity Sensor Breakout Board .. toctree:: :caption: Other Links diff --git a/examples/ahtx0_simpletest.py b/examples/ahtx0_simpletest.py index 2d44043..c835127 100644 --- a/examples/ahtx0_simpletest.py +++ b/examples/ahtx0_simpletest.py @@ -1,12 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +""" +Basic `AHTx0` example test +""" + import time import board +import busio import adafruit_ahtx0 # Create the sensor object using I2C -sensor = adafruit_ahtx0.AHTx0(board.I2C()) +i2c = busio.I2C(board.SCL, board.SDA) +sensor = adafruit_ahtx0.AHTx0(i2c) while True: print("\nTemperature: %0.1f C" % sensor.temperature)