diff --git a/README.rst b/README.rst index 490b8b8..9dae45e 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/adafruit_max31856.py b/adafruit_max31856.py index 8d8630d..5cc6a13 100644 --- a/adafruit_max31856.py +++ b/adafruit_max31856.py @@ -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 @@ -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. @@ -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 @@ -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] diff --git a/docs/examples.rst b/docs/examples.rst index 0d652e2..643e1f0 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -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: diff --git a/docs/index.rst b/docs/index.rst index 0590401..08db860 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,9 +23,13 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit Universal Thermocouple Amplifier MAX31856 Breakout Learning Guide + .. toctree:: :caption: Related Products + Adafruit Universal Thermocouple Amplifier MAX31856 Breakout + .. toctree:: :caption: Other Links diff --git a/examples/max31856_simpletest.py b/examples/max31856_simpletest.py index dad4685..a45c1f6 100644 --- a/examples/max31856_simpletest.py +++ b/examples/max31856_simpletest.py @@ -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) diff --git a/examples/max31856_thresholds_and_faults.py b/examples/max31856_thresholds_and_faults.py index 829e856..ef8ec4c 100644 --- a/examples/max31856_thresholds_and_faults.py +++ b/examples/max31856_thresholds_and_faults.py @@ -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)