Up テスト 作成: 2021-03-31
更新: 2021-03-31


    配線


    テスト用プログラム:dht11_test.py
#!/usr/bin/python import RPi.GPIO as GPIO from time import sleep import dht11 SignalPin = 18 delayTime = 5 def setup(): # Disable warning "This channel is already in use . . ." #GPIO.setwarnings(False) # Set the GPIO pins as numbering GPIO.setmode(GPIO.BOARD) def destroy(): # Release resource GPIO.cleanup() def loop(): instance = dht11.DHT11(pin = SignalPin) while True: sleep( delayTime ) #get DHT11 sensor value result = instance.read() print "Temperature = ",result.temperature,"C"," Humidity = ",result.humidity,"%" # The Program will start from here if __name__ == '__main__': setup() try: loop() # When control c is pressed child program destroy() will be executed. except KeyboardInterrupt: destroy()


    この中で import しているライブラリ dht11.py は,つぎのように取得する:
      $ sudo wget http://osoyoo.com/driver/dht11.py


    $ sudo chown pi dht11.py
    $ sudo chgrp pi dht11.py


    $ vi dht11_test.py

    $ chmod +x dht11_test.py

    $ ./dht11_test.py Temperature = 25 C Humidity = 42 % Temperature = 24 C Humidity = 42 % Temperature = 0 C Humidity = 0 % Temperature = 24 C Humidity = 42 % Temperature = 24 C Humidity = 42 % Temperature = 24 C Humidity = 42 % ^C