@@ -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,13 +114,15 @@ 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 len(pulse_in) >= 82 :
121
+ # break
122
+ if time .monotonic ()- tmono > 0.25 : # time out after 1/4 seconds
123
123
break
124
124
125
+ #print(len(pulse_in))
125
126
pulse_in .pause ()
126
127
while pulse_in :
127
128
pulses .append (pulse_in .popleft ())
@@ -137,11 +138,15 @@ def measure(self):
137
138
Raises RuntimeError exception for checksum failure and for insuffcient
138
139
data returned from the device (try again)
139
140
"""
140
- if time .monotonic ()- self ._last_called > 0.5 :
141
+ delay_between_readings = 0.5
142
+ if (self ._dht11 ):
143
+ delay_between_readings = 1.0
144
+ if time .monotonic ()- self ._last_called > delay_between_readings :
141
145
self ._last_called = time .monotonic ()
142
146
143
147
pulses = self ._get_pulses ()
144
- ##print(pulses)
148
+ #print(pulses)
149
+ #print(len(pulses))
145
150
146
151
if len (pulses ) >= 80 :
147
152
buf = array .array ('B' )
@@ -169,6 +174,7 @@ def measure(self):
169
174
# checksum is the last byte
170
175
if chk_sum & 0xff != buf [4 ]:
171
176
# check sum failed to validate
177
+ #print(pulses)
172
178
raise RuntimeError ("Checksum did not validate. Try again." )
173
179
#print("checksum did not match. Temp: {} Humidity: {} Checksum:{}"
174
180
#.format(self._temperature,self._humidity,bites[4]))
0 commit comments