Skip to content

Commit

Permalink
Merge pull request #28 from jposada202020/improving_docs
Browse files Browse the repository at this point in the history
improving_docs
  • Loading branch information
jposada202020 authored Apr 24, 2021
2 parents 8821a01 + e43a6a6 commit 1180fd5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
37 changes: 33 additions & 4 deletions adafruit_mcp9808.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit MCP9808 High Accuracy I2C Temperature Sensor Learning Guide <https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide>

.. toctree::
:caption: Related Products

Expand Down
5 changes: 2 additions & 3 deletions examples/mcp9808_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1180fd5

Please sign in to comment.