Skip to content

Commit 1180fd5

Browse files
Merge pull request #28 from jposada202020/improving_docs
improving_docs
2 parents 8821a01 + e43a6a6 commit 1180fd5

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ Usage Notes
5858
===========
5959

6060
Getting the temperature in Celsius is easy! First, import all of the pins from
61-
the board, busio for native I2C communication and the thermometer library
61+
the board, board.I2C() for native I2C communication and the thermometer library
6262
itself.
6363

6464
.. code-block:: python
6565
6666
from board import *
67-
import busio
6867
import adafruit_mcp9808
6968
7069
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:
7372
.. code-block:: python
7473
7574
# Do one reading
76-
with busio.I2C(SCL, SDA) as i2c:
75+
with i2c = board.I2C() as i2c:
7776
t = adafruit_mcp9808.MCP9808(i2c)
7877
7978
# Finally, read the temperature property and print it out

adafruit_mcp9808.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
`adafruit_mcp9808` - MCP9808 I2C Temperature Sensor
6+
`adafruit_mcp9808`
77
====================================================
88
99
CircuitPython library to support MCP9808 high accuracy temperature sensor.
@@ -20,7 +20,7 @@
2020
2121
**Software and Dependencies:**
2222
23-
* Adafruit CircuitPython firmware (0.8.0+) for the ESP8622 and M0-based boards:
23+
* Adafruit CircuitPython firmware for the supported boards:
2424
https://github.com/adafruit/circuitpython/releases
2525
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2626
@@ -43,7 +43,36 @@
4343

4444

4545
class MCP9808:
46-
"""Interface to the MCP9808 temperature sensor."""
46+
"""Interface to the MCP9808 temperature sensor.
47+
48+
:param ~busio.I2C i2c_bus: The I2C bus the MCP9808 is connected to.
49+
:param int address: The I2C address of the device. Defaults to :const:`0x18`
50+
51+
**Quickstart: Importing and using the MCP9808**
52+
53+
Here is an example of using the :class:`MCP9808` class.
54+
First you will need to import the libraries to use the sensor
55+
56+
.. code-block:: python
57+
58+
import board
59+
import adafruit_mcp9808
60+
61+
Once this is done you can define your `board.I2C` object and define your sensor object
62+
63+
.. code-block:: python
64+
65+
i2c = board.I2C() # uses board.SCL and board.SDA
66+
mcp = adafruit_mcp9808.MCP9808(i2c_bus)
67+
68+
Now you have access to the change in temperature using the
69+
:attr:`temperature` attribute. This temperature is in Celsius.
70+
71+
.. code-block:: python
72+
73+
temperature = mcp.temperature
74+
75+
"""
4776

4877
# alert_lower_temperature_bound
4978
# alert_upper_temperature_bound
@@ -75,7 +104,7 @@ def __init__(self, i2c_bus, address=0x18):
75104

76105
@property
77106
def temperature(self):
78-
"""Temperature in celsius. Read-only."""
107+
"""Temperature in Celsius. Read-only."""
79108
self.buf[0] = 0x05
80109
with self.i2c_device as i2c:
81110
i2c.write_then_readinto(self.buf, self.buf, out_end=1, in_start=1)

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Adafruit MCP9808 High Accuracy I2C Temperature Sensor Learning Guide <https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/mcp9808_simpletest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
import time
55
import board
6-
import busio
76
import adafruit_mcp9808
87

9-
i2c_bus = busio.I2C(board.SCL, board.SDA)
8+
i2c = board.I2C() # uses board.SCL and board.SDA
109

1110
# To initialise using the default address:
12-
mcp = adafruit_mcp9808.MCP9808(i2c_bus)
11+
mcp = adafruit_mcp9808.MCP9808(i2c)
1312

1413
# To initialise using a specified address:
1514
# Necessary when, for example, connecting A0 to VDD to make address=0x19

0 commit comments

Comments
 (0)