溫度感測器
-
1
sudo pip3 install Adafruit_DHT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import time import Adafruit_DHT GPIO_PIN = 4 try: print("--------------") while True: h, t = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11,GPIO_PIN) if h is not None and t is not None: print("temp={0:0.1f}".format(t)) else: print("fail,please retry") time.sleep(10) except KeyboarInterrupt: print('close')