Skip to content

Initial commit #1

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
Feb 14, 2017
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Radomir Dopieralski for Adafruit Industries
Copyright (c) 2017 Radomir Dopieralski, written for Adafruit Industries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
56 changes: 43 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,70 @@

Introduction
============

.. image:: https://readthedocs.org/projects/adafruit-circuitpython-MAX31855/badge/?version=latest
:target: https://circuitpython.readthedocs.io/projects/MAX31855/en/latest/
:alt: Documentation Status

.. image :: https://badges.gitter.im/adafruit/circuitpython.svg
.. image:: https://badges.gitter.im/adafruit/circuitpython.svg
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
:alt: Gitter

TODO

Dependencies
=============
This driver depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
This driver depends on the `Bus Device
<https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_ library.
Please ensure is is also available on the CircuitPython filesystem. This is
easily achieved by downloading `a library and driver bundle
<https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Usage Example
=============
Usage Notes
===========

Of course, you must import the library to use it:

.. code:: python

import adafruit_max31855

You also need to create an SPI interface object, and a pin object for the
chip select pin. You can use any pin for the CS, but we use D5 here:


.. code:: python

from nativeio import SPI, DigitalInOut
import board

spi = SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
cs = DigitalInOut(board.D5)

Next, just create the sensor object:

.. code:: python

sensor = adafruit_max31855.MAX31855(spi, cs)

And you can start making measurements:

.. code:: python

print(sensor.temperature)

The temperature is read in degrees Celsius (°C). You have to convert it to
other units yourself, if you need it.

TODO

Contributing
============

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_MAX31855/blob/master/CODE_OF_CONDUCT.md>`_
<https://github.com/adafruit/Adafruit_CircuitPython_MAX21855/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.


API Reference
=============

Expand Down
29 changes: 0 additions & 29 deletions adafruit_MAX31855.py

This file was deleted.

72 changes: 72 additions & 0 deletions adafruit_max31855.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Radomir Dopieralski for Adafruit Industries.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

"""
``adafruit_max31855``
=====================

This is a CircuitPython driver for the Maxim Integrated MAX31855 thermocouple
amplifier module.

"""

import ustruct

from adafruit_bus_device.spi_device import SPIDevice


class MAX31855:
"""
Driver for the MAX31855 thermocouple amplifier.
"""

def __init__(self, spi, cs):
self.spi_device = SPIDevice(spi, cs)
self.data = bytearray(4)

def _read(self, internal=False):
with self.spi_device as spi:
spi.readinto(self.data)
if self.data[3] & 0x01:
raise RuntimeError("thermocouple not connected")
if self.data[3] & 0x02:
raise RuntimeError("short circuit to ground")
if self.data[3] & 0x04:
raise RuntimeError("short circuit to power")
if self.data[1] & 0x01:
raise RuntimeError("faulty reading")
temp, refer = ustruct.unpack('>hh', self.data)
refer >>= 4
temp >>= 2
if internal:
return refer
return temp

@property
def temperature(self):
"""Thermocouple temperature in degrees Celsius."""
return self._read() / 4

@property
def reference_temperature(self):
"""Internal reference temperature in degrees Celsius."""
return self._read(True) * 0.625
2 changes: 0 additions & 2 deletions api.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

.. If you created a package, create one automodule per module in the package.

.. automodule:: adafruit_max31855
:members:
4 changes: 2 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# General information about the project.
project = u'Adafruit MAX31855 Library'
copyright = u'2017 Radomir Dopieralski'
author = u'Scott Shawcroft'
author = u'Radomir Dopieralski'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -118,7 +118,7 @@
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'AdafruitMAX31855Library.tex', u'Adafruit MAX31855 Library Documentation',
u'Phiilip Moyer', 'manual'),
u'Radomir Dopieralski', 'manual'),
]

# -- Options for manual page output ---------------------------------------
Expand Down