Help us understand the problem. What is going on with this article?

DHT11をラズパイ + pythonで使えるようにする(メモ)

More than 3 years have passed since last update.

DHT11

安価で導入できる温度湿度計DHT11をサクッと使うため、pythonライブラリを導入(ダウンロードするだけ)。

git clone https://github.com/szazo/DHT11_Python

上記で公開されているdht11_example.pyが、スタートプログラムになる。

dht11_example.py
import RPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin=14)

while True:
    result = instance.read()
    if result.is_valid():
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: %d C" % result.temperature)
        print("Humidity: %d %%" % result.humidity)

time.sleep(1)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away