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
36 changes: 31 additions & 5 deletions adafruit_am2320.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

**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://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

"""
Expand Down Expand Up @@ -63,8 +63,34 @@ def _crc16(data):
class AM2320:
"""A driver for the AM2320 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 AM2320 is connected to.
This is the only required parameter.
:param int address: (optional) The I2C address of the device. Defaults to :const:`0x5C`

**Quickstart: Importing and using the AM2320**

Here is an example of using the :class:`AM2320` class.
First you will need to import the libraries to use the sensor

.. code-block:: python

import board
import adafruit_am2320

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
am = adafruit_am2320.AM2320(i2c)

Now you have access to the temperature using :attr:`temperature` attribute and
the relative humidity using the :attr:`relative_humidity` attribute

.. code-block:: python

temperature = am.temperature
relative_humidity = am.relative_humidity

"""

Expand Down Expand Up @@ -108,7 +134,7 @@ def _read_register(self, register, length):

@property
def temperature(self):
"""The measured temperature in celsius."""
"""The measured temperature in Celsius."""
temperature = struct.unpack(">H", self._read_register(AM2320_REG_TEMP_H, 2))[0]
if temperature >= 32768:
temperature = 32768 - temperature
Expand Down
2 changes: 2 additions & 0 deletions 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 AM2320 Temperature and Humidity Sensor Learning Guide <https://learn.adafruit.com/adafruit-am2320-temperature-humidity-i2c-sensor/python-circuitpython>

.. toctree::
:caption: Related Products

Adafruit AM2320 Temperature and Humidity Sensor <https://www.adafruit.com/product/3721>

.. toctree::
:caption: Other Links
Expand Down
3 changes: 1 addition & 2 deletions examples/am2320_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_am2320

# create the I2C shared bus
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
am = adafruit_am2320.AM2320(i2c)

while True:
Expand Down