This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aa46202
Showing
8 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
dist/ | ||
*.egg-info | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Copyright (c) 2014 Adafruit Industries | ||
# Author: Tony DiCola | ||
# | ||
# 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. | ||
import logging | ||
import math | ||
|
||
import Adafruit_GPIO as GPIO | ||
import Adafruit_GPIO.SPI as SPI | ||
|
||
# Default I2C address for device. | ||
MCP9808_I2CADDR_DEFAULT = 0x18 | ||
|
||
# Register addresses. | ||
MCP9808_REG_CONFIG = 0x01 | ||
MCP9808_REG_UPPER_TEMP = 0x02 | ||
MCP9808_REG_LOWER_TEMP = 0x03 | ||
MCP9808_REG_CRIT_TEMP = 0x04 | ||
MCP9808_REG_AMBIENT_TEMP = 0x05 | ||
MCP9808_REG_MANUF_ID = 0x06 | ||
MCP9808_REG_DEVICE_ID = 0x07 | ||
|
||
# Configuration register values. | ||
MCP9808_REG_CONFIG_SHUTDOWN = 0x0100 | ||
MCP9808_REG_CONFIG_CRITLOCKED = 0x0080 | ||
MCP9808_REG_CONFIG_WINLOCKED = 0x0040 | ||
MCP9808_REG_CONFIG_INTCLR = 0x0020 | ||
MCP9808_REG_CONFIG_ALERTSTAT = 0x0010 | ||
MCP9808_REG_CONFIG_ALERTCTRL = 0x0008 | ||
MCP9808_REG_CONFIG_ALERTSEL = 0x0002 | ||
MCP9808_REG_CONFIG_ALERTPOL = 0x0002 | ||
MCP9808_REG_CONFIG_ALERTMODE = 0x0001 | ||
|
||
|
||
class MAX31855(object): | ||
"""Class to represent an Adafruit MAX31855 thermocouple temperature | ||
measurement board. | ||
""" | ||
|
||
def __init__(self, clk=None, cs=None, do=None, spi=None, gpio=None): | ||
"""Initialize MAX31855 device with software SPI on the specified CLK, | ||
CS, and DO pins. Alternatively can specify hardware SPI by sending an | ||
Adafruit_GPIO.SPI.SpiDev device in the spi parameter. | ||
""" | ||
self._logger = logging.getLogger('Adafruit_MAX31855.MAX31855') | ||
self._spi = None | ||
# Default to platform GPIO if not provided. | ||
self._gpio = gpio if gpio is not None else GPIO.get_platform_gpio() | ||
# Handle hardware SPI | ||
if spi is not None: | ||
self._logger.debug('Using hardware SPI') | ||
self._spi = spi | ||
elif clk is not None and cs is not None and do is not None: | ||
self._logger.debug('Using software SPI') | ||
self._spi = SPI.BitBang(self._gpio, clk, None, do, cs) | ||
else: | ||
raise ValueError('Must specify either spi for for hardware SPI or clk, cs, and do for softwrare SPI!') | ||
self._spi.set_mode(0) | ||
self._spi.set_bit_order(SPI.MSBFIRST) | ||
|
||
def readInternalC(self): | ||
"""Return internal temperature value in degrees celsius.""" | ||
v = self._read32() | ||
# Ignore bottom 4 bits of thermocouple data. | ||
v >>= 4 | ||
# Grab bottom 11 bits as internal temperature data. | ||
internal = v & 0x7FF | ||
if v & 0x800: | ||
# Negative value, take 2's compliment. Compute this with subtraction | ||
# because python is a little odd about handling signed/unsigned. | ||
internal -= 4096 | ||
# Scale by 0.0625 degrees C per bit and return value. | ||
return internal * 0.0625 | ||
|
||
def readTempC(self): | ||
"""Return the thermocouple temperature value in degrees celsius.""" | ||
v = self._read32() | ||
# Check for error reading value. | ||
if v & 0x7: | ||
return float('NaN') | ||
# Check if signed bit is set. | ||
if v & 0x80000000: | ||
# Negative value, take 2's compliment. Compute this with subtraction | ||
# because python is a little odd about handling signed/unsigned. | ||
v >>= 18 | ||
v -= 16384 | ||
else: | ||
# Positive value, just shift the bits to get the value. | ||
v >>= 18 | ||
# Scale by 0.25 degrees C per bit and return value. | ||
return v * 0.25 | ||
|
||
def _read32(self): | ||
# Read 32 bits from the SPI bus. | ||
raw = self._spi.read(4) | ||
if raw is None or len(raw) != 4: | ||
raise RuntimeError('Did not read expected number of bytes from device!') | ||
value = raw[0] << 24 | raw[1] << 16 | raw[2] << 8 | raw[3] | ||
self._logger.debug('Raw value: 0x{0:08X}'.format(value & 0xFFFFFFFF)) | ||
return value |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Adafruit Python MAX31855 | ||
======================== | ||
|
||
Python library for accessing the MAX31855 thermocouple temperature sensor on a Raspberry Pi or Beaglebone Black. | ||
|
||
Designed specifically to work with the Adafruit MAX31855 sensor ----> https://www.adafruit.com/products/269 | ||
|
||
To install, first make sure some dependencies are available by running the following commands (on a Raspbian | ||
or Beaglebone Black Debian install): | ||
|
||
```` | ||
sudo apt-get update | ||
sudo apt-get install build-essential python-dev python-smbus | ||
```` | ||
|
||
Then download the library by clicking the download zip link to the right and unzip the archive somewhere on your Raspberry Pi or Beaglebone Black. Then execute the following command in the directory of the library: | ||
|
||
```` | ||
sudo python setup.py install | ||
```` | ||
|
||
Make sure you have internet access on the device so it can download the required dependencies. | ||
|
||
See examples of usage in the examples folder. | ||
|
||
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! | ||
|
||
Written by Tony DiCola for Adafruit Industries. | ||
MIT license, all text above must be included in any redistribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python | ||
# Copyright (c) 2014 Adafruit Industries | ||
# Author: Tony DiCola | ||
# | ||
# 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. | ||
|
||
# Can enable debug output by uncommenting: | ||
#import logging | ||
#logging.basicConfig(level=logging.DEBUG) | ||
|
||
import time | ||
|
||
import Adafruit_MAX31855.MAX31855 as MAX31855 | ||
|
||
|
||
# Raspberry Pi software SPI configuration. | ||
CLK = 25 | ||
CS = 24 | ||
DO = 18 | ||
|
||
# Initialize the sensor with software SPI. | ||
sensor = MAX31855.MAX31855(CLK, CS, DO) | ||
|
||
# Loop printing measurements every second. | ||
print 'Press Ctrl-C to quit.' | ||
while True: | ||
print 'Thermocouple Temperature: {0:0.4F} *C'.format(sensor.readTempC()) | ||
print ' Internal Temperature: {0:0.4F} *C'.format(sensor.readInternalC()) | ||
time.sleep(1.0) |
Oops, something went wrong.