Skip to content

Commit f12e925

Browse files
authored
Merge pull request #9 from jposada202020/using_reset
Changes on the _chip_id
2 parents 9a15caf + 69ab50f commit f12e925

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

adafruit_shtc3.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def __init__(self, i2c_bus):
118118
self.low_power = False
119119
self.sleeping = False
120120
self.reset()
121-
if self._chip_id & 0x083F != _SHTC3_CHIP_ID:
121+
self._chip_id = self._get_chip_id()
122+
if self._chip_id != _SHTC3_CHIP_ID:
122123
raise RuntimeError("Failed to find an SHTC3 sensor - check your wiring!")
123124

124125
def _write_command(self, command):
@@ -129,18 +130,14 @@ def _write_command(self, command):
129130
with self.i2c_device as i2c:
130131
i2c.write(self._buffer, start=0, end=2)
131132

132-
@property
133-
def _chip_id(self): # readCommand(SHTC3_READID, data, 3);
133+
def _get_chip_id(self): # readCommand(SHTC3_READID, data, 3);
134134
"""Determines the chip id of the sensor"""
135-
self._buffer[0] = _SHTC3_READID >> 8
136-
self._buffer[1] = _SHTC3_READID & 0xFF
137-
135+
self._write_command(_SHTC3_READID)
136+
time.sleep(0.001)
138137
with self.i2c_device as i2c:
139-
i2c.write_then_readinto(
140-
self._buffer, self._buffer, out_start=0, out_end=2, in_start=0, in_end=2
141-
)
138+
i2c.readinto(self._buffer)
142139

143-
return unpack_from(">H", self._buffer)[0]
140+
return unpack_from(">H", self._buffer)[0] & 0x083F
144141

145142
def reset(self):
146143
"""Perform a soft reset of the sensor, resetting all settings to their power-on defaults"""

0 commit comments

Comments
 (0)