取得溫濕度
DHT22(AOSONG AM2302) 溫濕度元件在GitHub中有提供Raspberry Pi的python的程式讀取溫度與濕度
更新系統套件
執行指令:
sudo apt-get update
sudo apt-get upgrade接著要安裝所需要的相關套件
執行指令:
sudo apt-get install git build-essential python-dev執行結果:
pi@raspberrypi:~ $ sudo apt-get install git build-essential python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.3).
The following additional packages will be installed:
git-man liberror-perl libexpat1-dev libpython-dev libpython2.7 libpython2.7-dev python2.7-dev
Suggested packages:
git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
git git-man liberror-perl libexpat1-dev libpython-dev libpython2.7 libpython2.7-dev python-dev python2.7-dev
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 33.7 MB of archives.
After this operation, 67.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf liberror-perl all 0.17024-1 [26.9 kB]
Get:2 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf git-man all 1:2.11.0-3+deb9u2 [1,432 kB]
Get:9 http://raspbian.raspberrypi.org/raspbian stretch/main armhf python-dev armhf 2.7.13-2 [1,130 B]
Get:3 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf git armhf 1:2.11.0-3+deb9u2 [3,380 kB]
Get:4 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libexpat1-dev armhf 2.2.0-2+deb9u1 [116 kB]
Get:5 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libpython2.7 armhf 2.7.13-2+deb9u2 [914 kB]
Get:6 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libpython2.7-dev armhf 2.7.13-2+deb9u2 [27.6 MB]
Get:7 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libpython-dev armhf 2.7.13-2 [20.0 kB]
Get:8 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf python2.7-dev armhf 2.7.13-2+deb9u2 [286 kB]
Fetched 33.7 MB in 37s (911 kB/s)
Selecting previously unselected package liberror-perl.
(Reading database ... 34374 files and directories currently installed.)
Preparing to unpack .../0-liberror-perl_0.17024-1_all.deb ...
Unpacking liberror-perl (0.17024-1) ...
Selecting previously unselected package git-man.
Preparing to unpack .../1-git-man_1%3a2.11.0-3+deb9u2_all.deb ...
Unpacking git-man (1:2.11.0-3+deb9u2) ...
Selecting previously unselected package git.
Preparing to unpack .../2-git_1%3a2.11.0-3+deb9u2_armhf.deb ...
Unpacking git (1:2.11.0-3+deb9u2) ...
Selecting previously unselected package libexpat1-dev:armhf.
Preparing to unpack .../3-libexpat1-dev_2.2.0-2+deb9u1_armhf.deb ...
Unpacking libexpat1-dev:armhf (2.2.0-2+deb9u1) ...
Selecting previously unselected package libpython2.7:armhf.
Preparing to unpack .../4-libpython2.7_2.7.13-2+deb9u2_armhf.deb ...
Unpacking libpython2.7:armhf (2.7.13-2+deb9u2) ...
Selecting previously unselected package libpython2.7-dev:armhf.
Preparing to unpack .../5-libpython2.7-dev_2.7.13-2+deb9u2_armhf.deb ...
Unpacking libpython2.7-dev:armhf (2.7.13-2+deb9u2) ...
Selecting previously unselected package libpython-dev:armhf.
Preparing to unpack .../6-libpython-dev_2.7.13-2_armhf.deb ...
Unpacking libpython-dev:armhf (2.7.13-2) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../7-python2.7-dev_2.7.13-2+deb9u2_armhf.deb ...
Unpacking python2.7-dev (2.7.13-2+deb9u2) ...
Selecting previously unselected package python-dev.
Preparing to unpack .../8-python-dev_2.7.13-2_armhf.deb ...
Unpacking python-dev (2.7.13-2) ...
Setting up git-man (1:2.11.0-3+deb9u2) ...
Setting up liberror-perl (0.17024-1) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Setting up libpython2.7:armhf (2.7.13-2+deb9u2) ...
Setting up libexpat1-dev:armhf (2.2.0-2+deb9u1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libpython2.7-dev:armhf (2.7.13-2+deb9u2) ...
Setting up python2.7-dev (2.7.13-2+deb9u2) ...
Setting up git (1:2.11.0-3+deb9u2) ...
Setting up libpython-dev:armhf (2.7.13-2) ...
Setting up python-dev (2.7.13-2) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
pi@raspberrypi:~ $下載程式碼
以上所需要的套件安裝完成後,透過git指令把放在github上的程式clone到Raspberry Pi中
執行指令:
執行結果:
安裝Adafruit_Python_DHT
執行指令:
執行結果:
取得溫濕度
執行指令:
執行結果:
所顯示的Temp就是目前所讀取到的溫度,而Humidity就是濕度
Last updated
Was this helpful?