From 5a390ab3a27327131e8fbef5d2b977c5af7c6a2d Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Fri, 1 Dec 2017 15:52:35 -0800 Subject: [PATCH] Small fixes. --- .gitignore | 1 + adafruit_max31865.py | 10 +++++----- examples/simpletest.py | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 92d3065..260f9bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ _build *.pyc +*.mpy diff --git a/adafruit_max31865.py b/adafruit_max31865.py index fe25916..948f7cb 100644 --- a/adafruit_max31865.py +++ b/adafruit_max31865.py @@ -71,10 +71,10 @@ class MAX31865: def __init__(self, spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2): self.rtd_nominal = rtd_nominal - self.red_resistor = ref_resistor + self.ref_resistor = ref_resistor self._device = spi_device.SPIDevice(spi, cs) # Set wire config register based on the number of wires specified. - if wires not in _WIRE_MAP: + if wires not in (2, 3, 4): raise ValueError('Wires must be a value of 2, 3, or 4!') t = self._read_u8(_MAX31865_CONFIG_REG) if wires == 3: @@ -91,7 +91,7 @@ class MAX31865: # Read an 8-bit unsigned value from the specified 8-bit address. with self._device as device: device.configure(baudrate=500000, phase=1, polarity=0) - _BUFFER[0] = address & 0x7F + self._BUFFER[0] = address & 0x7F device.write(self._BUFFER, end=1) device.readinto(self._BUFFER, end=1) return self._BUFFER[0] @@ -111,7 +111,7 @@ class MAX31865: device.configure(baudrate=500000, phase=1, polarity=0) self._BUFFER[0] = (address & 0xFF) | 0x80 self._BUFFER[1] = val & 0xFF - self._device.write(self._BUFFER, end=2) + device.write(self._BUFFER, end=2) @property def bias(self): @@ -124,7 +124,7 @@ class MAX31865: if val: t |= _MAX31865_CONFIG_BIAS # Enable bias. else: - t &= ~MAX31865_CONFIG_BIAS # Disable bias. + t &= ~_MAX31865_CONFIG_BIAS # Disable bias. self._write_u8(_MAX31865_CONFIG_REG, t) @property diff --git a/examples/simpletest.py b/examples/simpletest.py index 26f51e3..e7bef0a 100644 --- a/examples/simpletest.py +++ b/examples/simpletest.py @@ -2,6 +2,7 @@ # Will print the temperature every second. import board import busio +import digitalio import time import adafruit_max31865 @@ -9,7 +10,7 @@ import adafruit_max31865 # Initialize SPI bus and sensor. spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) -cs = board.D5 # Chip select of the MAX31865 board. +cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31865 board. sensor = adafruit_max31865.MAX31865(spi, cs) # Note you can optionally provide the thermocouple RTD nominal, the reference # resistance, and the number of wires for the sensor (2 the default, 3, or 4) @@ -21,6 +22,6 @@ while True: # Read temperature. temp = sensor.temperature # Print the value. - print('Temperature: {0.3f}C'.format(temp)) + print('Temperature: {0:0.3f}C'.format(temp)) # Delay for a second. time.sleep(1.0)