Advertisement
Guest User

10.04.2016 Pythin: DHT22 on Raspberry Pi (Vcc Pin 12)

a guest
Apr 10th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import time
  5. import Adafruit_DHT
  6. import RPi.GPIO as GPIO
  7.  
  8. GPIO.setwarnings(False)
  9. GPIO.setmode(GPIO.BOARD)
  10. GPIO.setup(12, GPIO.OUT)
  11. GPIO.output(12, GPIO.HIGH)
  12.  
  13. time.sleep(2)
  14. humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 17)
  15.  
  16. i = 0
  17.  
  18. while humidity is None and temperature is None and i<10:
  19. i += 1
  20. GPIO.output(12, GPIO.LOW)
  21. time.sleep(3)
  22. GPIO.output(12, GPIO.HIGH)
  23. time.sleep(3)
  24. humidity, temperature = Adafruit_DHT.read(Adafruit_DHT.DHT22, 17)
  25.  
  26. if humidity is not None and temperature is not None:
  27. print ('{0:.{1}f}'.format((temperature*10),0))
  28. print ('{0:.{1}f}'.format((humidity*10),0))
  29. print '0'
  30. print 'Bathroom Temp+Hum'
  31. else:
  32. print '0'
  33. print '0'
  34. print '0'
  35. print 'Bath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement