import time import board import adafruit_dht # 데이터 핀 3번을 사용면, GPIO2로 설정 pin = board.D2 dhtDevice = adafruit_dht.DHT11(pin) while True: try: # 온도 및 습도 값을 읽어옴 temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity print( "온도: {:.1f} F / {:.1f} C 습도: {}% ".format( temperature_f, temperature_c, humidity ) ) except RuntimeError as error: # 오류 발생 시 계속 진행 print(error.args[0]) time.sleep(2.0) continue except Exception as error: # 예기치 않은 오류 시 종료 dhtDevice.exit() raise error time.sleep(2.0)