DHT11.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Rpi-envMonitor 作者: conanwhf 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号