Skip to content

Instantly share code, notes, and snippets.

@aula9
Created August 26, 2018 17:08
Show Gist options
  • Save aula9/81cd60cfb62178bfb13cfb906fccbe0c to your computer and use it in GitHub Desktop.
Save aula9/81cd60cfb62178bfb13cfb906fccbe0c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import time
import Adafruit_CharLCD as LCD
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 23
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Raspberry Pi pin configuration:
lcd_rs = 24
lcd_en = 25
lcd_d4 = 17
lcd_d5 = 27
lcd_d6 = 22
lcd_d7 = 10
lcd_backlight = 2
lcd_columns = 16 #Lcd column
lcd_rows = 2 #number of LCD rows
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, lcd_backlight)
# Print a two line message
lcd.message('Hello\nworld!')
# Wait 5 seconds
time.sleep(2)
lcd.clear()
lcd.message('humidity,temperature')
while True:
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
lcd.message(str(temperature))
time.sleep(5.0)
lcd.clear()
lcd.message(str(humidity))
time.sleep(2)
lcd.clear()
lcd.message('humidity,temperature')
else:
print('Failed to get reading. Try again!')
lcd.clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment