more G-Labs products

Author Topic: LCD 1602 PCF8574  (Read 1610 times)

March 30, 2016, 03:32:20 PM
Read 1610 times

atom

  • *
  • Information
  • Newbie
  • Posts: 5
Hello everyone, trying to install LCD 1602 PCF8574 I2C, using the package "HD 44780 LCD PCF 8574" by changing the address on your "var address = 0x27", but it does not work, an error   `object' does not contain a definition for `Pins'

March 30, 2016, 04:47:33 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I have no idea, but I would first search for where you are using "Pins" to see what it's referring to.  Perhaps it's expecting "Pins" and you aren't providing it so you won't find anything.

March 31, 2016, 09:14:57 AM
Reply #2

atom

  • *
  • Information
  • Newbie
  • Posts: 5
I also have a working script in Python, how to add it to HomeGenie?

Code: [Select]
#!/usr/bin/env python

import Adafruit_DHT as dht
import datetime
import time
import lcddriver

#Variables
sleepsecs = 30 #how many seconds to wait between each sensor query

lcd = lcddriver.lcd()

#Print welcome text on display
lcd.lcd_clear()
lcd.lcd_display_string("       Loading", 1)
lcd.lcd_display_string("   temperature and", 2)
lcd.lcd_display_string("     humidity log", 3)

#Write csv header
print "Datetime;Temp;Humidity"

#Function to "draw" a temperature or humidity bar on display
def draw_bar(value, line, low_limit, high_limit, bar_max_value):
char_width = 20 #display width in chars
bar_max_value = bar_max_value * 1.0

#Get character position for values
value_on_char = round(value / bar_max_value * char_width)
low_limit_on_char = round(low_limit / bar_max_value * char_width)
high_limit_on_char = round(high_limit / bar_max_value * char_width)

#Build string that comprises the bar
streng = ""
for i in range(0, char_width):
if i == value_on_char and (i > high_limit_on_char or i < low_limit_on_char):
streng = streng + "!"
elif i == value_on_char:
streng = streng + "*"
elif i > high_limit_on_char or i < low_limit_on_char:
streng = streng + "="
else:
streng = streng + "-"

#Write the bar to display on given line
lcd.lcd_display_string(streng, line)

#Main program loop
while True:
#Get current date and time
now = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')

#Read values from sensor
h,t = dht.read_retry(dht.DHT22, 4)

#Print date/time, temperature and humidity separated by semicolon
print now + ';{0:0.1f};{1:0.1f}'.format(t, h)

#Write temp, humidity to display
lcd.lcd_clear()
lcd.lcd_display_string("{0:0.1f} *C - {1:0.1f}%".format(t, h), 1)
#Draw temp, humidity bars to display
draw_bar(t, 2, 5, 21, 40) #temperature: value line low high bar_max
draw_bar(h, 3, 30, 50, 100) #humidity: value line low high bar_max
#Write date/time to display
lcd.lcd_display_string(now, 4)

#Wait sleepsecs seconds before repeating loop
time.sleep(sleepsecs)