From e43a6a67dc97bb82f6ab401c16d82b972197c032 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 24 Apr 2021 18:39:06 -0400 Subject: [PATCH] improving_docs --- README.rst | 5 ++--- adafruit_mcp9808.py | 37 ++++++++++++++++++++++++++++++---- docs/index.rst | 2 ++ examples/mcp9808_simpletest.py | 5 ++--- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 6edf71e..ca8984c 100644 --- a/README.rst +++ b/README.rst @@ -58,13 +58,12 @@ Usage Notes =========== Getting the temperature in Celsius is easy! First, import all of the pins from -the board, busio for native I2C communication and the thermometer library +the board, board.I2C() for native I2C communication and the thermometer library itself. .. code-block:: python from board import * - import busio import adafruit_mcp9808 Next, initialize the I2C bus in a with statement so it always gets shut down ok. @@ -73,7 +72,7 @@ Then, construct the thermometer class: .. code-block:: python # Do one reading - with busio.I2C(SCL, SDA) as i2c: + with i2c = board.I2C() as i2c: t = adafruit_mcp9808.MCP9808(i2c) # Finally, read the temperature property and print it out diff --git a/adafruit_mcp9808.py b/adafruit_mcp9808.py index 3ce4b66..80275c9 100644 --- a/adafruit_mcp9808.py +++ b/adafruit_mcp9808.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT """ -`adafruit_mcp9808` - MCP9808 I2C Temperature Sensor +`adafruit_mcp9808` ==================================================== CircuitPython library to support MCP9808 high accuracy temperature sensor. @@ -20,7 +20,7 @@ **Software and Dependencies:** -* Adafruit CircuitPython firmware (0.8.0+) for the ESP8622 and M0-based boards: +* 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 @@ -43,7 +43,36 @@ class MCP9808: - """Interface to the MCP9808 temperature sensor.""" + """Interface to the MCP9808 temperature sensor. + + :param ~busio.I2C i2c_bus: The I2C bus the MCP9808 is connected to. + :param int address: The I2C address of the device. Defaults to :const:`0x18` + + **Quickstart: Importing and using the MCP9808** + + Here is an example of using the :class:`MCP9808` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_mcp9808 + + 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 + mcp = adafruit_mcp9808.MCP9808(i2c_bus) + + Now you have access to the change in temperature using the + :attr:`temperature` attribute. This temperature is in Celsius. + + .. code-block:: python + + temperature = mcp.temperature + + """ # alert_lower_temperature_bound # alert_upper_temperature_bound @@ -75,7 +104,7 @@ def __init__(self, i2c_bus, address=0x18): @property def temperature(self): - """Temperature in celsius. Read-only.""" + """Temperature in Celsius. Read-only.""" self.buf[0] = 0x05 with self.i2c_device as i2c: i2c.write_then_readinto(self.buf, self.buf, out_end=1, in_start=1) diff --git a/docs/index.rst b/docs/index.rst index a7a6140..f371c24 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit MCP9808 High Accuracy I2C Temperature Sensor Learning Guide + .. toctree:: :caption: Related Products diff --git a/examples/mcp9808_simpletest.py b/examples/mcp9808_simpletest.py index 7875d97..6fa99ef 100644 --- a/examples/mcp9808_simpletest.py +++ b/examples/mcp9808_simpletest.py @@ -3,13 +3,12 @@ import time import board -import busio import adafruit_mcp9808 -i2c_bus = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA # To initialise using the default address: -mcp = adafruit_mcp9808.MCP9808(i2c_bus) +mcp = adafruit_mcp9808.MCP9808(i2c) # To initialise using a specified address: # Necessary when, for example, connecting A0 to VDD to make address=0x19