repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dht22.py 898B

1234567891011121314151617181920212223242526272829
  1. import time
  2. import board
  3. import adafruit_dht
  4. # connect Device
  5. dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False)
  6. # you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
  7. # This may be necessary on a Linux single board computer like the Raspberry Pi,
  8. # but it will not work in CircuitPython.
  9. # dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
  10. while True:
  11. try:
  12. # Print the values to the serial port
  13. temperature_c = dhtDevice.temperature
  14. humidity = dhtDevice.humidity
  15. print("Temp: {:.1f} C Humidity: {}% ".format(temperature_c, humidity))
  16. except RuntimeError as error:
  17. # Errors happen fairly often, DHT's are hard to read, just keep going
  18. print(error.args[0])
  19. time.sleep(2.0)
  20. continue
  21. except Exception as error:
  22. dhtDevice.exit()
  23. raise error
  24. time.sleep(2.0)