LoginSignup
0
0

More than 3 years have passed since last update.

Grove - Temperature&Humidity Sensor(DHT11)をRaspberry Piで使用する

Last updated at Posted at 2020-11-23

はじめに

HAT基盤と温度センサーを買ったのはよかったけど、動かしていなかったので、動作検証代わりに行った。

お値段等
* 千石電商 Grove Base Hat for Raspberry Pi ¥1304
* Grove - デジタル温度・湿度センサー ¥662

Grove Base Hat for Raspberry Piの準備

Seeed Studioの商品ページを参考に
以下のコマンドを入力してセットアップをする。

curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -

実行しばらく待つと以下のメッセージが表示される。

Successfully installed grove.py-0.6
#######################################################
  Lastest Grove.py from github install complete   !!!!!
#######################################################

Grove - Temperature&Humidity Sensor(DHT11)を動作する。

Seeed Studioの商品ページを参考にして、
センサーをHat基盤のPWMに接続をする。

以下のコマンドでライブラリをインストールする。

git clone https://github.com/Seeed-Studio/Seeed_Python_DHT.git
cd Seeed_Python_DHT
sudo python setup.py install

インストールしたら以下の通りメッセージが表示される。

Installed /usr/local/lib/python2.7/dist-packages/seeed_python_dht-0.0.1-py2.7.egg
Processing dependencies for seeed-python-dht==0.0.1
Finished processing dependencies for seeed-python-dht==0.0.1

サンプルコードがgitからコピーしたフォルダ内にあるので、実行する

python examples/dht_simpleread.py

実行すると以下の通り温度と湿度を返す。

DHT11, humidity 66.0%, temperature 23.0*
DHT11, humidity 68.0%, temperature 21.0*
DHT11, humidity 74.0%, temperature 21.0*
DHT11, humidity 74.0%, temperature 21.0*

余談

goで温度を測定するプログラムは以下のサイトを参考にする
https://github.com/d2r2/go-dht

example1のサンプルコードで以下の修正を加えて

sensorType := dht.DHT11
pin := 12

rootユーザで実行すれば温度・湿度測定ができる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0