From 2baef10bd5eccaa1556fc5818daba1eb26fe0780 Mon Sep 17 00:00:00 2001 From: Kyle Luiten Date: Fri, 26 Jul 2024 14:47:53 -0700 Subject: [PATCH 1/2] Create max31855_circuitpython.py Add CircuitPython library support for MAX31855 input --- mycodo/inputs/max31855_circuitpython.py | 127 ++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 mycodo/inputs/max31855_circuitpython.py diff --git a/mycodo/inputs/max31855_circuitpython.py b/mycodo/inputs/max31855_circuitpython.py new file mode 100644 index 000000000..19653b846 --- /dev/null +++ b/mycodo/inputs/max31855_circuitpython.py @@ -0,0 +1,127 @@ +# coding=utf-8 +import copy + +from mycodo.inputs.base_input import AbstractInput + +# Measurements +measurements_dict = { + 0: { + 'measurement': 'temperature', + 'unit': 'C', + 'name': 'Object' + }, + 1: { + 'measurement': 'temperature', + 'unit': 'C', + 'name': 'Die' + } +} + +# Input information +INPUT_INFORMATION = { + 'input_name_unique': 'MAX31855_CIRCUITPYTHON', + 'input_manufacturer': 'MAXIM', + 'input_name': 'MAX31855', + 'input_library': 'adafruit-circuitpython-max31855', + 'measurements_name': 'Temperature (Object/Die)', + 'measurements_dict': measurements_dict, + 'url_manufacturer': 'https://www.maximintegrated.com/en/products/interface/sensor-interface/MAX31855.html', + 'url_datasheet': 'https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf', + 'url_product_purchase': 'https://www.adafruit.com/product/269', + 'options_enabled': [ + 'measurements_select', + 'period', + 'pre_output' + ], + 'options_disabled': ['interface'], + + 'dependencies_module': [ + ('pip-pypi', 'adafruit_max31855', 'adafruit-circuitpython-max31855==3.2.21') + ], + + 'interfaces': ['SPI'], + + 'custom_options': [ + { + 'id': 'cs_pin', + 'type': 'integer', + 'default_value': 5, + 'name': 'Chip Select Pin', + 'phrase': 'Enter the GPIO Chip Select Pin for your device.' + } + ] +} + + +class InputModule(AbstractInput): + """A sensor support class that measures the MAX31855's temperature.""" + def __init__(self, input_dev, testing=False): + super().__init__(input_dev, testing=testing, name=__name__) + + self.sensor = None + self.spi = None + self.cs = None + self.cs_pin = None + + if not testing: + self.setup_custom_options( + INPUT_INFORMATION['custom_options'], input_dev) + self.try_initialize() + + def initialize(self): + import board + import digitalio + import adafruit_max31855 + + bcm_to_board = [ + board.D1, + board.D2, + board.D3, + board.D4, + board.D5, + board.D6, + board.D7, + board.D8, + board.D9, + board.D10, + board.D11, + board.D12, + board.D13, + board.D14, + board.D15, + board.D16, + board.D17, + board.D18, + board.D19, + board.D20, + board.D21, + board.D22, + board.D23, + board.D24, + board.D25, + board.D26, + board.D27 + ] + + self.spi = board.SPI() + self.cs = digitalio.DigitalInOut(bcm_to_board[self.cs_pin - 1]) + + self.sensor = adafruit_max31855.MAX31855( + self.spi, + self.cs) + + def get_measurement(self): + """Gets the measurement in units by reading the.""" + if not self.sensor: + self.logger.error("Error 101: Device not set up. See https://kizniche.github.io/Mycodo/Error-Codes#error-101 for more info.") + return + + self.return_dict = copy.deepcopy(measurements_dict) + + if self.is_enabled(0): + self.value_set(0, self.sensor.temperature) + + if self.is_enabled(1): + self.value_set(1, self.sensor.reference_temperature) + + return self.return_dict From 0fd97f153cb855d0cb06a8de0d618e3b6a1b3e06 Mon Sep 17 00:00:00 2001 From: Kyle Luiten Date: Fri, 26 Jul 2024 15:22:42 -0700 Subject: [PATCH 2/2] Update max31855_circuitpython.py Removed unnecessary whitespace. --- mycodo/inputs/max31855_circuitpython.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mycodo/inputs/max31855_circuitpython.py b/mycodo/inputs/max31855_circuitpython.py index 19653b846..88f4e02f7 100644 --- a/mycodo/inputs/max31855_circuitpython.py +++ b/mycodo/inputs/max31855_circuitpython.py @@ -34,13 +34,12 @@ 'pre_output' ], 'options_disabled': ['interface'], - 'dependencies_module': [ ('pip-pypi', 'adafruit_max31855', 'adafruit-circuitpython-max31855==3.2.21') ], 'interfaces': ['SPI'], - + 'custom_options': [ { 'id': 'cs_pin',