From b6e62c15f8b2e61496dd3fd517f3259c38eee7dc Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 14 Apr 2021 08:35:01 -0400 Subject: [PATCH 1/3] Changes on the _chip_id --- adafruit_shtc3.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_shtc3.py b/adafruit_shtc3.py index 757804b..ad0059a 100644 --- a/adafruit_shtc3.py +++ b/adafruit_shtc3.py @@ -107,6 +107,8 @@ def _chip_id(self): # readCommand(SHTC3_READID, data, 3); self._buffer[0] = _SHTC3_READID >> 8 self._buffer[1] = _SHTC3_READID & 0xFF + self.reset() + with self.i2c_device as i2c: i2c.write_then_readinto( self._buffer, self._buffer, out_start=0, out_end=2, in_start=0, in_end=2 From 98f68152e008ed0cc0751c721f01f6563336021e Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 14 Apr 2021 20:54:10 -0400 Subject: [PATCH 2/3] Changing chip_id function. --- adafruit_shtc3.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/adafruit_shtc3.py b/adafruit_shtc3.py index cce6627..6e75653 100644 --- a/adafruit_shtc3.py +++ b/adafruit_shtc3.py @@ -118,6 +118,7 @@ def __init__(self, i2c_bus): self.low_power = False self.sleeping = False self.reset() + self._chip_id = self._get_chip_id() if self._chip_id & 0x083F != _SHTC3_CHIP_ID: raise RuntimeError("Failed to find an SHTC3 sensor - check your wiring!") @@ -129,18 +130,12 @@ def _write_command(self, command): with self.i2c_device as i2c: i2c.write(self._buffer, start=0, end=2) - @property - def _chip_id(self): # readCommand(SHTC3_READID, data, 3); + def _get_chip_id(self): # readCommand(SHTC3_READID, data, 3); """Determines the chip id of the sensor""" - self._buffer[0] = _SHTC3_READID >> 8 - self._buffer[1] = _SHTC3_READID & 0xFF - - self.reset() - + self._write_command(_SHTC3_READID) + time.sleep(0.001) with self.i2c_device as i2c: - i2c.write_then_readinto( - self._buffer, self._buffer, out_start=0, out_end=2, in_start=0, in_end=2 - ) + i2c.readinto(self._buffer) return unpack_from(">H", self._buffer)[0] From 69ab50f48cd98c9496adf3c5aa2e057005c03500 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 15 Apr 2021 13:19:29 -0400 Subject: [PATCH 3/3] Getting the chip ID --- adafruit_shtc3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_shtc3.py b/adafruit_shtc3.py index 6e75653..93ef783 100644 --- a/adafruit_shtc3.py +++ b/adafruit_shtc3.py @@ -119,7 +119,7 @@ def __init__(self, i2c_bus): self.sleeping = False self.reset() self._chip_id = self._get_chip_id() - if self._chip_id & 0x083F != _SHTC3_CHIP_ID: + if self._chip_id != _SHTC3_CHIP_ID: raise RuntimeError("Failed to find an SHTC3 sensor - check your wiring!") def _write_command(self, command): @@ -137,7 +137,7 @@ def _get_chip_id(self): # readCommand(SHTC3_READID, data, 3); with self.i2c_device as i2c: i2c.readinto(self._buffer) - return unpack_from(">H", self._buffer)[0] + return unpack_from(">H", self._buffer)[0] & 0x083F def reset(self): """Perform a soft reset of the sensor, resetting all settings to their power-on defaults"""