embeded/raspberry pi2023. 9. 19. 14:18

저장소 손보고

pi@raspberrypi:~/src $ sudo apt-get update
Get:1 http://archive.raspberrypi.org/debian bullseye InRelease [23.6 kB]
Get:2http://raspbian.raspberrypi.org/raspbian bullseye InRelease [15.0 kB]
Get:3 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf Packages [13.2 MB]
Get:4 http://archive.raspberrypi.org/debian bullseye/main armhf Packages [314 kB]
Fetched 13.6 MB in 25s (534 kB/s)                                                                                                
Reading package lists... Done
N: Repository ' http://raspbian.raspberrypi.org/raspbian bullseye InRelease' changed its 'Suite' value from 'stable' to 'oldstable'

pi@raspberrypi:~/src $ sudo apt full-upgrade

[링크 : https://forums.raspberrypi.com/viewtopic.php?t=318302]

 

pip를 이용하여 패키지 설치하고

$ sudo apt-get install python3-pip

[링크 : https://foreverhappiness.tistory.com/67] // pip3가 아니다 ㅠㅠ

 

adafruit_dht 패키지 설치하고

sudo pip3 install Adafruit_DHT
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Adafruit_DHT
  Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB)
Building wheels for collected packages: Adafruit-DHT
  Building wheel for Adafruit-DHT (setup.py) ... done
  Created wheel for Adafruit-DHT: filename=Adafruit_DHT-1.4.0-cp39-cp39-linux_armv7l.whl size=26725 sha256=6d328e4cac264d9807d07a3f20bbc7eb687bf002ae850b3dcfdae1d5fc4a9a64
  Stored in directory: /root/.cache/pip/wheels/2b/75/fa/27f8bc06878df2b751d348ad98e92361f78ea9f9640c7e6277
Successfully built Adafruit-DHT
Installing collected packages: Adafruit-DHT
Successfully installed Adafruit-DHT-1.4.0

 

소스는 adafruit 에서 만든걸 써서 별거 없는데

import Adafruit_DHT as dht
import time

while True:
    humidity, temperature = dht.read_retry(dht.DHT22, 4)
    print("Temp={0:0.1f}*C  Humidity={1:0.1f}%".format(temperature, humidity))   
time.sleep(1)

[링크 : https://kdjun97.github.io/iot/raspberry-pi-dht22/]

 

예상외로 읽는데 실패가 좀 많은지 의외로 빈번하게 4초 정도 걸리는 경우가 나온다.

pi@raspberrypi:~/src $ time python sen.py 
Temp=26.6*C  Humidity=55.6%
Temperature in Celsius : 26.74 C
Pressure : 1003.37 hPa

real 0m3.937s
user 0m0.370s
sys 0m0.060s

pi@raspberrypi:~/src $ time python sen.py 
Temp=26.6*C  Humidity=55.5%
Temperature in Celsius : 26.74 C
Pressure : 1003.42 hPa

real 0m1.415s
user 0m0.352s
sys 0m0.058s

 

python 에서 멀티 쓰레드로 해서 읽어오게 해야하나..

'embeded > raspberry pi' 카테고리의 다른 글

서보 pan/tilt 조립  (0) 2023.09.23
서보 팬틸트 브라켓 구매  (0) 2023.09.19
bmp280 HW-611  (0) 2023.09.19
라즈베리 파이 openOCD jtag?  (0) 2023.07.24
rpi bear metal  (0) 2023.07.10
Posted by 구차니