KRITSADA

Raspberry pi Humi_Temp VEC No2

Dec 24th, 2015
4,544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import time
  2. import Adafruit_DHT
  3. import datetime
  4. Sensor = Adafruit_DHT.DHT11
  5. GPIO = 17
  6. h=0
  7. t=0
  8. while True:
  9.     humidity, temperature = Adafruit_DHT.read_retry(Sensor,GPIO)
  10.     if humidity is not None and temperature is not None:
  11.         #print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature,humidity))
  12.         h=humidity
  13.         t=temperature
  14.     else:
  15.         print('Failed to get reading. Try again!')
  16.     date=datetime.datetime.now()
  17.     with open("Logger.txt", "a") as text_file:
  18.         text_file.write("DetaTime: %s Humid: %.2f %% Temp: %.2f C\n" % (date.strftime("%Y-%M-%d : %H:%M:%S"),h,t))
  19.         print("DetaTime: %s Humid: %.2f %% Temp: %.2f C" % (date.strftime("%Y-%M-%d : %H:%M:%S"),h,t))
  20.     time.sleep(10)
Add Comment
Please, Sign In to add comment