Small fixes.

This commit is contained in:
Tony DiCola 2017-12-01 15:52:35 -08:00
parent e6d413dc58
commit 5a390ab3a2
3 changed files with 9 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__ __pycache__
_build _build
*.pyc *.pyc
*.mpy

View File

@ -71,10 +71,10 @@ class MAX31865:
def __init__(self, spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2): def __init__(self, spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=2):
self.rtd_nominal = rtd_nominal self.rtd_nominal = rtd_nominal
self.red_resistor = ref_resistor self.ref_resistor = ref_resistor
self._device = spi_device.SPIDevice(spi, cs) self._device = spi_device.SPIDevice(spi, cs)
# Set wire config register based on the number of wires specified. # 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!') raise ValueError('Wires must be a value of 2, 3, or 4!')
t = self._read_u8(_MAX31865_CONFIG_REG) t = self._read_u8(_MAX31865_CONFIG_REG)
if wires == 3: if wires == 3:
@ -91,7 +91,7 @@ class MAX31865:
# Read an 8-bit unsigned value from the specified 8-bit address. # Read an 8-bit unsigned value from the specified 8-bit address.
with self._device as device: with self._device as device:
device.configure(baudrate=500000, phase=1, polarity=0) device.configure(baudrate=500000, phase=1, polarity=0)
_BUFFER[0] = address & 0x7F self._BUFFER[0] = address & 0x7F
device.write(self._BUFFER, end=1) device.write(self._BUFFER, end=1)
device.readinto(self._BUFFER, end=1) device.readinto(self._BUFFER, end=1)
return self._BUFFER[0] return self._BUFFER[0]
@ -111,7 +111,7 @@ class MAX31865:
device.configure(baudrate=500000, phase=1, polarity=0) device.configure(baudrate=500000, phase=1, polarity=0)
self._BUFFER[0] = (address & 0xFF) | 0x80 self._BUFFER[0] = (address & 0xFF) | 0x80
self._BUFFER[1] = val & 0xFF self._BUFFER[1] = val & 0xFF
self._device.write(self._BUFFER, end=2) device.write(self._BUFFER, end=2)
@property @property
def bias(self): def bias(self):
@ -124,7 +124,7 @@ class MAX31865:
if val: if val:
t |= _MAX31865_CONFIG_BIAS # Enable bias. t |= _MAX31865_CONFIG_BIAS # Enable bias.
else: else:
t &= ~MAX31865_CONFIG_BIAS # Disable bias. t &= ~_MAX31865_CONFIG_BIAS # Disable bias.
self._write_u8(_MAX31865_CONFIG_REG, t) self._write_u8(_MAX31865_CONFIG_REG, t)
@property @property

View File

@ -2,6 +2,7 @@
# Will print the temperature every second. # Will print the temperature every second.
import board import board
import busio import busio
import digitalio
import time import time
import adafruit_max31865 import adafruit_max31865
@ -9,7 +10,7 @@ import adafruit_max31865
# Initialize SPI bus and sensor. # Initialize SPI bus and sensor.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 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) sensor = adafruit_max31865.MAX31865(spi, cs)
# Note you can optionally provide the thermocouple RTD nominal, the reference # 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) # resistance, and the number of wires for the sensor (2 the default, 3, or 4)
@ -21,6 +22,6 @@ while True:
# Read temperature. # Read temperature.
temp = sensor.temperature temp = sensor.temperature
# Print the value. # Print the value.
print('Temperature: {0.3f}C'.format(temp)) print('Temperature: {0:0.3f}C'.format(temp))
# Delay for a second. # Delay for a second.
time.sleep(1.0) time.sleep(1.0)