@@ -100,7 +100,6 @@ def _get_pulses(self):
100
100
pulses will have 81 elements for the DHT11/22 type devices.
101
101
"""
102
102
pulses = array .array ('H' )
103
- tmono = time .monotonic ()
104
103
105
104
# create the PulseIn object using context manager
106
105
with pulseio .PulseIn (self ._pin , 81 , True ) as pulse_in :
@@ -115,11 +114,10 @@ def _get_pulses(self):
115
114
pulse_in .resume (self ._trig_wait )
116
115
117
116
# loop until we get the return pulse we need or
118
- # time out after 1/2 seconds
117
+ # time out after 1/4 second
118
+ tmono = time .monotonic ()
119
119
while True :
120
- if len (pulse_in ) >= 80 :
121
- break
122
- if time .monotonic ()- tmono > 0.5 : # time out after 1/2 seconds
120
+ if time .monotonic ()- tmono > 0.25 : # time out after 1/4 seconds
123
121
break
124
122
125
123
pulse_in .pause ()
@@ -137,25 +135,26 @@ def measure(self):
137
135
Raises RuntimeError exception for checksum failure and for insuffcient
138
136
data returned from the device (try again)
139
137
"""
140
- if time .monotonic ()- self ._last_called > 0.5 :
138
+ delay_between_readings = 0.5
139
+ if self ._dht11 :
140
+ delay_between_readings = 1.0
141
+ if time .monotonic ()- self ._last_called > delay_between_readings :
141
142
self ._last_called = time .monotonic ()
142
143
143
144
pulses = self ._get_pulses ()
144
- ##print(pulses)
145
145
146
146
if len (pulses ) >= 80 :
147
147
buf = array .array ('B' )
148
148
for byte_start in range (0 , 80 , 16 ):
149
149
buf .append (self ._pulses_to_binary (pulses , byte_start , byte_start + 16 ))
150
- #print(buf)
151
150
152
151
# humidity is 2 bytes
153
152
if self ._dht11 :
154
153
self ._humidity = buf [0 ]
155
154
else :
156
155
self ._humidity = ((buf [0 ]<< 8 ) | buf [1 ]) / 10
157
156
158
- # tempature is 2 bytes
157
+ # temperature is 2 bytes
159
158
if self ._dht11 :
160
159
self ._temperature = buf [2 ]
161
160
else :
@@ -170,15 +169,10 @@ def measure(self):
170
169
if chk_sum & 0xff != buf [4 ]:
171
170
# check sum failed to validate
172
171
raise RuntimeError ("Checksum did not validate. Try again." )
173
- #print("checksum did not match. Temp: {} Humidity: {} Checksum:{}"
174
- #.format(self._temperature,self._humidity,bites[4]))
175
172
176
- # checksum matches
177
- #print("Temp: {} C Humidity: {}% ".format(self._temperature, self._humidity))
178
173
179
174
else :
180
175
raise RuntimeError ("A full buffer was not returned. Try again." )
181
- #print("did not get a full return. number returned was: {}".format(len(r)))
182
176
183
177
@property
184
178
def temperature (self ):
0 commit comments