25
25
26
26
27
27
28
- # * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29
- # * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
28
+ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29
+ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
30
30
"""
31
31
32
32
# imports
80
80
class SHTC3 :
81
81
"""
82
82
A driver for the SHTC3 temperature and humidity sensor.
83
- :param i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
84
- :param int address: (optional) The I2C address of the device.
83
+
84
+ :param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
85
+
85
86
"""
86
87
87
88
def __init__ (self , i2c_bus ):
@@ -90,7 +91,7 @@ def __init__(self, i2c_bus):
90
91
self ._buffer = bytearray (6 )
91
92
self .low_power = False
92
93
self .reset ()
93
- self .sleep = False
94
+ self .sleeping = False
94
95
if self ._chip_id & 0x083F != _SHTC3_CHIP_ID :
95
96
raise RuntimeError ("Failed to find an ICM20X sensor - check your wiring!" )
96
97
@@ -124,12 +125,12 @@ def reset(self):
124
125
time .sleep (0.001 )
125
126
126
127
@property
127
- def sleep (self ):
128
+ def sleeping (self ):
128
129
"""Determines the sleep state of the sensor"""
129
130
return self ._cached_sleep
130
131
131
- @sleep .setter
132
- def sleep (self , sleep_enabled ):
132
+ @sleeping .setter
133
+ def sleeping (self , sleep_enabled ):
133
134
if sleep_enabled :
134
135
self ._write_command (_SHTC3_SLEEP )
135
136
else :
@@ -150,19 +151,19 @@ def low_power(self, low_power_enabled):
150
151
151
152
@property
152
153
def relative_humidity (self ):
153
- """Current relative humidity in % rH"""
154
+ """The current relative humidity in % rH"""
154
155
return self .measurements [1 ]
155
156
156
157
@property
157
158
def temperature (self ):
158
- """Current temperature in degrees celcius"""
159
+ """The current temperature in degrees celcius"""
159
160
return self .measurements [0 ]
160
161
161
162
@property
162
163
def measurements (self ):
163
164
"""both `temperature` and `relative_humidity`, read simultaneously"""
164
165
165
- self .sleep = False
166
+ self .sleeping = False
166
167
temperature = None
167
168
humidity = None
168
169
# send correct command for the current power state
@@ -193,16 +194,16 @@ def measurements(self):
193
194
# decode data into human values:
194
195
# convert bytes into 16-bit signed integer
195
196
# convert the LSB value to a human value according to the datasheet
196
- raw_temp = unpack_from (">h" , temp_data )
197
+ raw_temp = unpack_from (">h" , temp_data )[ 0 ]
197
198
raw_temp = ((4375 * raw_temp ) >> 14 ) - 4500
198
199
temperature = raw_temp / 100.0
199
200
200
201
# repeat above steps for humidity data
201
- raw_humidity = unpack_from (">h" , humidity_data )
202
+ raw_humidity = unpack_from (">h" , humidity_data )[ 0 ]
202
203
raw_humidity = (625 * raw_humidity ) >> 12
203
204
humidity = raw_humidity / 100.0
204
205
205
- self .sleep = True
206
+ self .sleeping = True
206
207
return (temperature , humidity )
207
208
208
209
## CRC-8 formula from page 14 of SHTC3 datasheet
@@ -211,7 +212,6 @@ def measurements(self):
211
212
212
213
@staticmethod
213
214
def _crc8 (buffer ):
214
- print ("\t \t buff" , [hex (i ) for i in buffer ])
215
215
crc = 0xFF
216
216
for byte in buffer :
217
217
crc ^= byte
@@ -220,5 +220,4 @@ def _crc8(buffer):
220
220
crc = (crc << 1 ) ^ 0x31
221
221
else :
222
222
crc = crc << 1
223
- print ("\t \t crc:" , hex (crc & 0xFF ))
224
223
return crc & 0xFF # return the bottom 8 bits
0 commit comments