Skip to content

improving_docs #13

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 25, 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
28 changes: 14 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ To install in a virtual environment in your current project:

Usage Example
=============
::

import board
import busio
import digitalio
import adafruit_max31856
.. code:: python3

# create a spi object
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
import board
import digitalio
import adafruit_max31856

# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OUTPUT
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()

# create a thermocouple object with the above
thermocouple = adafruit_max31856.MAX31856(spi, cs)
# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OUTPUT

# print the temperature!
print(thermocouple.temperature)
# create a thermocouple object with the above
thermocouple = adafruit_max31856.MAX31856(spi, cs)

# print the temperature!
print(thermocouple.temperature)


Contributing
Expand Down
39 changes: 33 additions & 6 deletions adafruit_max31856.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

"""

from time import sleep
Expand Down Expand Up @@ -108,11 +109,37 @@ class ThermocoupleType: # pylint: disable=too-few-public-methods
class MAX31856:
"""Driver for the MAX31856 Universal Thermocouple Amplifier

:param ~busio.SPI spi_bus: The SPI bus the MAX31856 is connected to.
:param ~microcontroller.Pin cs: The pin used for the CS signal.
:param ~adafruit_max31856.ThermocoupleType thermocouple_type: The type of thermocouple.\
:param ~busio.SPI spi: The SPI bus the MAX31856 is connected to.
:param ~microcontroller.Pin cs: The pin used for the CS signal.
:param ~adafruit_max31856.ThermocoupleType thermocouple_type: The type of thermocouple.\
Default is Type K.

**Quickstart: Importing and using the MAX31856**

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

.. code-block:: python

import board
from digitalio import DigitalInOut, Direction
import adafruit_max31856

Once this is done you can define your `board.SPI` object and define your sensor object

.. code-block:: python

spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31856 board.
sensor = adafruit_max31856.MAX31856(spi, cs)


Now you have access to the :attr:`temperature` attribute

.. code-block:: python

temperature = sensor.temperature

"""

# A class level buffer to reduce allocations for reading and writing.
Expand All @@ -137,7 +164,7 @@ def __init__(self, spi, cs, thermocouple_type=ThermocoupleType.K):

@property
def temperature(self):
"""The temperature of the sensor and return its value in degrees celsius. (read-only)"""
"""The temperature of the sensor and return its value in degrees Celsius. (read-only)"""
self._perform_one_shot_measurement()

# unpack the 3-byte temperature as 4 bytes
Expand All @@ -155,7 +182,7 @@ def temperature(self):

@property
def reference_temperature(self):
"""The temperature of the cold junction in degrees celsius. (read-only)"""
"""The temperature of the cold junction in degrees Celsius. (read-only)"""
self._perform_one_shot_measurement()

raw_read = unpack(">h", self._read_register(_MAX31856_CJTH_REG, 2))[0]
Expand Down
9 changes: 9 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/max31856_simpletest.py
:caption: examples/max31856_simpletest.py
:linenos:

Thresholds and Fault example
----------------------------

Example showing how to use thresholds

.. literalinclude:: ../examples/max31856_thresholds_and_faults.py
:caption: examples/max31856_thresholds_and_faults.py
:linenos:
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit Universal Thermocouple Amplifier MAX31856 Breakout Learning Guide <https://learn.adafruit.com/adafruit-max31856-thermocouple-amplifier>

.. toctree::
:caption: Related Products

Adafruit Universal Thermocouple Amplifier MAX31856 Breakout <https://www.adafruit.com/product/3263>

.. toctree::
:caption: Other Links

Expand Down
5 changes: 2 additions & 3 deletions examples/max31856_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# SPDX-License-Identifier: MIT

import board
import busio
import digitalio
import adafruit_max31856

# create a spi object
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()

# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D5)
Expand Down
5 changes: 2 additions & 3 deletions examples/max31856_thresholds_and_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import time
import board
import busio
import digitalio
import adafruit_max31856

# create a spi object
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()

# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D0)
Expand Down