def _read_data(self):
self.data=[]
# reset
GPIO.setup( self.pin , GPIO.OUT)
GPIO.output( self.pin , GPIO.LOW)
time.sleep(0.03) # ????18ms
GPIO.setup( self.pin , GPIO.IN)
count=0
while GPIO.input( self.pin ) == GPIO.HIGH:
continue
while GPIO.input( self.pin ) == GPIO.LOW:
continue
# ????80us???????
while GPIO.input( self.pin ) == GPIO.HIGH:
count += 1
continue
base = count / 2
# Get data
while len(self.data)< DHT11_DATA_LEN*8:
i = 0
# ??50us?????
while GPIO.input( self.pin ) == GPIO.LOW:
continue
# ?????????26-28us??0?????70us??1
while GPIO.input( self.pin ) == GPIO.HIGH:
i += 1
if i > 100: #?????
break
if i < base:
self.data.append(0)
else:
self.data.append(1)
#print("DHT11 get data: ", self.data)
评论列表
文章目录