Skip to content

Commit b894f03

Browse files
committed
Initial commit
1 parent 9d00228 commit b894f03

File tree

6 files changed

+118
-47
lines changed

6 files changed

+118
-47
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 Radomir Dopieralski for Adafruit Industries
3+
Copyright (c) 2017 Radomir Dopieralski, written for Adafruit Industries
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.rst

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
1-
21
Introduction
32
============
43

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

9-
.. image :: https://badges.gitter.im/adafruit/circuitpython.svg
8+
.. image:: https://badges.gitter.im/adafruit/circuitpython.svg
109
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
1110
:alt: Gitter
1211

13-
TODO
1412

1513
Dependencies
1614
=============
17-
This driver depends on:
1815

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

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

26-
Usage Example
27-
=============
23+
Usage Notes
24+
===========
25+
26+
Of course, you must import the library to use it:
27+
28+
.. code:: python
29+
30+
import adafruit_max31855
31+
32+
You also need to create an SPI interface object, and a pin object for the
33+
chip select pin. You can use any pin for the CS, but we use D5 here:
34+
35+
36+
.. code:: python
37+
38+
from nativeio import SPI, DigitalInOut
39+
import board
40+
41+
spi = SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
42+
cs = DigitalInOut(board.D5)
43+
44+
Next, just create the sensor object:
45+
46+
.. code:: python
47+
48+
sensor = adafruit_max31855.MAX31855(spi, cs)
49+
50+
And you can start making measurements:
51+
52+
.. code:: python
53+
54+
print(sensor.temperature)
55+
56+
The temperature is read in degrees Celsius (°C). You have to convert it to
57+
other units yourself, if you need it.
2858

29-
TODO
3059

3160
Contributing
3261
============
3362

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

67+
3868
API Reference
3969
=============
4070

adafruit_MAX31855.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

adafruit_max31855.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2017 Radomir Dopieralski for Adafruit Industries.
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
"""
24+
``adafruit_max31855``
25+
=====================
26+
27+
This is a CircuitPython driver for the Maxim Integrated MAX31855 thermocouple
28+
amplifier module.
29+
30+
"""
31+
32+
import ustruct
33+
34+
from adafruit_bus_device.spi_device import SPIDevice
35+
36+
37+
class MAX31855:
38+
"""
39+
Driver for the MAX31855 thermocouple amplifier.
40+
"""
41+
42+
def __init__(self, spi, cs):
43+
self.spi_device = SPIDevice(spi, cs)
44+
self.data = bytearray(4)
45+
46+
def _read(self, internal=False):
47+
with self.spi_device as spi:
48+
spi.readinto(self.data)
49+
if self.data[3] & 0x01:
50+
raise RuntimeError("thermocouple not connected")
51+
if self.data[3] & 0x02:
52+
raise RuntimeError("short circuit to ground")
53+
if self.data[3] & 0x04:
54+
raise RuntimeError("short circuit to power")
55+
if self.data[1] & 0x01:
56+
raise RuntimeError("faulty reading")
57+
temp, refer = ustruct.unpack('>hh', self.data)
58+
refer >>= 4
59+
temp >>= 2
60+
if internal:
61+
return refer
62+
return temp
63+
64+
@property
65+
def temperature(self):
66+
"""Thermocouple temperature in degrees Celsius."""
67+
return self._read() / 4
68+
69+
@property
70+
def reference_temperature(self):
71+
"""Internal reference temperature in degrees Celsius."""
72+
return self._read(True) * 0.625

api.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11

2-
.. If you created a package, create one automodule per module in the package.
3-
42
.. automodule:: adafruit_max31855
53
:members:

conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# General information about the project.
2929
project = u'Adafruit MAX31855 Library'
3030
copyright = u'2017 Radomir Dopieralski'
31-
author = u'Scott Shawcroft'
31+
author = u'Radomir Dopieralski'
3232

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

124124
# -- Options for manual page output ---------------------------------------

0 commit comments

Comments
 (0)