온습도 센서 연결하기
페이지 정보

본문
종류에 따라 연결방식이 다름
참고사이트 : http://www.acronet.kr/24632
https://www.thegeekpub.com/236867/using-the-dht11-temperature-sensor-with-the-raspberry-pi/
------------------------------------------
> sudo apt-get install python3-dev python3-pip
> sudo python3 -m pip install --upgrade pip setuptools weel
> sudo pip3 install Adafruit_DHT (구 모듈)
> sudo pip3 install adafruit-circuitpython-dht (새 모듈)
참고사이트 : https://github.com/adafruit/Adafruit_CircuitPython_DHT
------------------------------------------
구 모듈 이용한 소스
import Adafruit_DHT
import time
from datetime import datetime
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
PROBE_NAME = "PI4"
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("{2} - T={0:0.1f} H={1:0.1f}".format(temperature, humidity, datetime.now()))
else:
print("Failed to retrieve data from humidity sensor")
------------------------------------------
두번째 소스
import Adafruit_DHT
import time
DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4
while True:
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Check wiring.");
time.sleep(3);
------------------------------------------
에러발생시
/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/platform_detect.py
파일을 열어서, 하단의
------------------------------------------------
else:
# Something else, not a pi.
return None
아래로 교체
else:
# Something else, PI 4 MODEL B
return 3
------------------------------------------------
------------------------------------------
신 모듈 이용하기
import adafruit_dht
import time
dht_device = adafruit_dht.DHT11(4)
#dht_device = adafruit_dht.DHT22(4)
try:
while True:
t = dht_device.temperature
h = dht_device.humidity
print ("t=>", t, " h=>", h)
time.sleep(100)
except KeyboardInterrupt:
print("Terminated by Keyboard")
finally:
print("End of Program")
------------------------------------------
소스 실행 에러 발생시
참고사이트 : https://github.com/adafruit/Adafruit_CircuitPython_DHT/issues/29
/home/pi/dht-sensor-service/.env/lib/python3.7/site-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/libgpiod_pulsein: error while loading shared libraries: libgpiod.so.2: cannot open shared object file: No such file or directory
Traceback (most recent call last):
================================================================
> sudo apt-get install libgpiod2
> apt-cache search libgpiod
================================================================
- 이전글WebIOPi 설치 20.10.12
- 다음글Raspberry Pi GPIO 활용하기 (쉘 스크립트) 20.10.07
댓글목록
등록된 댓글이 없습니다.