Skip to content

Commit 0b99d4c

Browse files
committed
fixing resolutions
1 parent 78fde91 commit 0b99d4c

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

adafruit_htu31d.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def humidity_resolution(self) -> Literal["0.020%", "0.014%", "0.010%", "0.007%"]
202202
203203
"""
204204

205-
return _HTU31D_HUMIDITY_RES[self._conversion_command >> 4 & 3]
205+
return _HTU31D_HUMIDITY_RES[self._conversion_command >> 3 & 3]
206206

207207
@humidity_resolution.setter
208208
def humidity_resolution(
@@ -212,9 +212,9 @@ def humidity_resolution(
212212
raise ValueError(
213213
f"Humidity resolution must be one of: {_HTU31D_HUMIDITY_RES}"
214214
)
215-
register = self._conversion_command & 0xCF
215+
register = self._conversion_command & 0xE7
216216
hum_res = _HTU31D_HUMIDITY_RES.index(value)
217-
self._conversion_command = register | hum_res << 4
217+
self._conversion_command = register | hum_res << 3
218218

219219
@property
220220
def temp_resolution(self) -> Literal["0.040", "0.025", "0.016", "0.012"]:
@@ -229,7 +229,7 @@ def temp_resolution(self) -> Literal["0.040", "0.025", "0.016", "0.012"]:
229229
230230
"""
231231

232-
return _HTU31D_TEMP_RES[self._conversion_command >> 2 & 3]
232+
return _HTU31D_TEMP_RES[self._conversion_command >> 1 & 3]
233233

234234
@temp_resolution.setter
235235
def temp_resolution(
@@ -239,9 +239,9 @@ def temp_resolution(
239239
raise ValueError(
240240
f"Temperature resolution must be one of: {_HTU31D_TEMP_RES}"
241241
)
242-
register = self._conversion_command & 0xF3
242+
register = self._conversion_command & 0xF9
243243
temp_res = _HTU31D_TEMP_RES.index(value)
244-
self._conversion_command = register | temp_res << 2
244+
self._conversion_command = register | temp_res << 1
245245

246246
@staticmethod
247247
def _crc(value) -> int:

examples/htu31d_setting_resolutions.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import time
56
import board
67
import adafruit_htu31d
78

@@ -24,7 +25,24 @@
2425
# Possible values are "0.020%", "0.014%", "0.010%" and "0.007%"
2526
htu.humidity_resolution = "0.007%"
2627

27-
28-
# Printing the New Values
2928
print("Temperature Resolution: ", htu.temp_resolution)
3029
print("Humidity Resolution: ", htu.humidity_resolution)
30+
31+
hum_res = ["0.020%", "0.014%", "0.010%", "0.007%"]
32+
temp_res = ["0.040", "0.025", "0.016", "0.012"]
33+
34+
while True:
35+
for humidity_resolution in hum_res:
36+
print(f"Current Humidity Resolution: {humidity_resolution}")
37+
for _ in range(3):
38+
print(f"Humidity: {htu.relative_humidity:.2f}")
39+
print(f"Temperature: {htu.temperature:.2f}")
40+
print("")
41+
time.sleep(0.5)
42+
for temperature_resolution in temp_res:
43+
print(f"Current Temperature Resolution: {temperature_resolution}")
44+
for _ in range(3):
45+
print(f"Humidity: {htu.relative_humidity:.2f}")
46+
print(f"Temperature: {htu.temperature:.2f}")
47+
print("")
48+
time.sleep(0.5)

0 commit comments

Comments
 (0)