X-Git-Url: http://russells-world.com/code/?p=rb-clock.git;a=blobdiff_plain;f=python%2Flcd-test.py;fp=python%2Flcd-test.py;h=9dcad184e7021ea9c1579089fe809d336b4e0947;hp=0000000000000000000000000000000000000000;hb=d29015560feafdb91746173de224a5fe692f7b6b;hpb=f2580fcc9470d1ac688ca9b6edd87666784eaf6b diff --git a/python/lcd-test.py b/python/lcd-test.py new file mode 100644 index 0000000..9dcad18 --- /dev/null +++ b/python/lcd-test.py @@ -0,0 +1,45 @@ +import RPi.GPIO as GPIO +from RPLCD.gpio import CharLCD +import socket +import fcntl +import struct +import time +from signal import signal, SIGINT +from sys import exit + +lcd = CharLCD(cols=20, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23], numbering_mode=GPIO.BOARD) +lcd.clear() + +def handler(signal_received, frame): + lcd.close() + print('SIGINT or CTRL-C detected. Exiting gracefully') + exit(0) + +def get_ip_address(ifname): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, + struct.pack('256s', ifname[:15]) + )[20:24]) + +if __name__ == '__main__': + signal(SIGINT, handler) + while True: + for i in range(0,6): + lcd.clear() + lcd.write_string("Time: %s" %time.strftime("%H:%M:%S")) + lcd.cursor_pos = (1, 0) + lcd.write_string("Date: %s" %time.strftime("%m/%d/%Y")) + time.sleep(1) + lcd.clear() + lcd.write_string("IP Address:") + lcd.cursor_pos = (1, 0) + lcd.write_string(get_ip_address('eth0')) + time.sleep(5) + +#lcd.clear() +#lcd.write_string(u'Hello world!') +#lcd.crlf() +#lcd.write_string(u'Hello world!') +lcd.close()