溫度感測器
-
sudo pip3 install Adafruit_DHT
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')