From b9684b6f67db5d158407e3d92f437530d8f2ebc5 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 4 May 2021 09:34:18 -0400 Subject: [PATCH 1/2] verifying_references --- README.rst | 20 ++++++++++---------- adafruit_adt7410.py | 12 ++++++++---- examples/adt7410_simpletest.py | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 035ecdc..fca8f75 100644 --- a/README.rst +++ b/README.rst @@ -55,19 +55,19 @@ To install in a virtual environment in your current project: Usage Example ============= -.. code-block:: python +.. code-block:: python3 - import time - import board - import adafruit_adt7410 + import time + import board + import adafruit_adt7410 - i2c_bus = board.I2C() - adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) - adt.high_resolution = True + i2c = board.I2C() # uses board.SCL and board.SDA + adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) + adt.high_resolution = True - while True: - print(adt.temperature) - time.sleep(0.5) + while True: + print(adt.temperature) + time.sleep(0.5) Contributing diff --git a/adafruit_adt7410.py b/adafruit_adt7410.py index f3a644f..dcf54a2 100644 --- a/adafruit_adt7410.py +++ b/adafruit_adt7410.py @@ -16,17 +16,21 @@ **Hardware:** -* `Adafruit's ADT7410 analog temperature Sensor Breakout: +* `Adafruit ADT7410 analog temperature Sensor Breakout `_ (Product ID: 4089) + **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases + https://circuitpython.org/downloads + +* Adafruit's Bus Device library: + https://github.com/adafruit/Adafruit_CircuitPython_BusDevice -* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice +* Adafruit's Register library: + https://github.com/adafruit/Adafruit_CircuitPython_Register -* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register """ diff --git a/examples/adt7410_simpletest.py b/examples/adt7410_simpletest.py index 29c87e7..a44a764 100644 --- a/examples/adt7410_simpletest.py +++ b/examples/adt7410_simpletest.py @@ -5,8 +5,8 @@ import board import adafruit_adt7410 -i2c_bus = board.I2C() -adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) +i2c = board.I2C() # uses board.SCL and board.SDA +adt = adafruit_adt7410.ADT7410(i2c, address=0x48) adt.high_resolution = True while True: From 15e28611610909b50b2bc6efc2d0057dca0607b3 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sun, 16 May 2021 21:00:31 -0400 Subject: [PATCH 2/2] adding_temp_crit --- adafruit_adt7410.py | 73 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/adafruit_adt7410.py b/adafruit_adt7410.py index dcf54a2..22156aa 100644 --- a/adafruit_adt7410.py +++ b/adafruit_adt7410.py @@ -9,7 +9,7 @@ CircuitPython driver for reading temperature from the Analog Devices ADT7410 precision temperature sensor -* Author(s): ladyada +* Author(s): ladyada, Jose David M. Implementation Notes -------------------- @@ -48,6 +48,13 @@ _ADT7410_TEMPLSB = const(0x1) _ADT7410_STATUS = const(0x2) _ADT7410_CONFIG = const(0x3) +_ADT7410_THIGHMSB = const(0x4) +_ADT7410_THIGHLSB = const(0x5) +_ADT7410_TLOWMSB = const(0x6) +_ADT7410_TLOWLSB = const(0x7) +_ADT7410_TCRITMSB = const(0x8) +_ADT7410_TCRITLSB = const(0x9) +_ADT7410_THYST = const(0x0A) _ADT7410_ID = const(0xB) _ADT7410_SWRST = const(0x2F) @@ -89,6 +96,10 @@ class ADT7410: intpin_polarity = RWBit(_ADT7410_CONFIG, 3) comparator_mode = RWBit(_ADT7410_CONFIG, 4) high_resolution = RWBit(_ADT7410_CONFIG, 7) + # Status Information configuration + temp_over_critiq = ROBit(_ADT7410_STATUS, 6) + temp_over_high = ROBit(_ADT7410_STATUS, 5) + temp_under_low = ROBit(_ADT7410_STATUS, 4) def __init__(self, i2c_bus, address=0x48): self.i2c_device = I2CDevice(i2c_bus, address) @@ -120,7 +131,7 @@ def configuration(self): @configuration.setter def configuration(self, val): - return self._write_register(_ADT7410_CONFIG, val) + self._write_register(_ADT7410_CONFIG, val) def reset(self): """Perform a software reset""" @@ -143,3 +154,61 @@ def _write_register(self, addr, data=None): end = 2 with self.i2c_device as i2c: i2c.write(self._buf, end=end) + + @property + def high_temperature(self): + """The over temperature limit value in Celsius""" + temp = self._read_register(_ADT7410_THIGHMSB, 2) + return struct.unpack(">h", temp)[0] / 128 + + @high_temperature.setter + def high_temperature(self, value): + value = struct.pack(">h", int(value * 128)) + self._write_register(_ADT7410_THIGHMSB, value[0]) + self._write_register(_ADT7410_THIGHLSB, value[1]) + + @property + def low_temperature(self): + """The over temperature limit value in Celsius. Only works when + comparator mode is selected""" + temp = self._read_register(_ADT7410_TLOWMSB, 2) + return struct.unpack(">h", temp)[0] / 128 + + @low_temperature.setter + def low_temperature(self, value): + value = struct.pack(">h", int(value * 128)) + self._write_register(_ADT7410_TLOWMSB, value[0]) + self._write_register(_ADT7410_TLOWLSB, value[1]) + + @property + def critical_temperature(self): + """The critical temperature limit value in Celsius. Only works when + comparator mode is selected""" + temp = self._read_register(_ADT7410_TCRITMSB, 2) + return struct.unpack(">h", temp)[0] / 128 + + @critical_temperature.setter + def critical_temperature(self, value): + """The over temperature limit value in Celsius + There is a bug in the sensor, so the address 0x09 could no be written to 0x00 + for this reason only odd numbers could be given. We could make the 0x09 with + a value of 0x01, however make the logic more complex. Only works when + comparator mode is selected + """ + value = struct.pack(">h", int(value * 128)) + self._write_register(_ADT7410_TCRITMSB, value[0]) + self._write_register(_ADT7410_TCRITLSB, value[1]) + + @property + def hysteresis(self): + """The hysteresis temperature limit value in Celsius. Only works when + comparator mode is selected. From 0 to 15 Celsius""" + temp = self._read_register(_ADT7410_THYST)[0] + return temp + + @hysteresis.setter + def hysteresis(self, value): + if value > 15 or isinstance(value, float): + raise Exception("Hysteresis value must be an integer lower than 15 Celsius") + + self._write_register(_ADT7410_THYST, value)