From a1b674100668707cbe23ab966b5350e6f04bf673 Mon Sep 17 00:00:00 2001 From: Mario Hoffmann Date: Thu, 24 Oct 2019 21:15:03 +0200 Subject: [PATCH] - Switched over to python3, which is just an adjustment of the README, some dependency and added shebang. - Fixed a missing import in datetime.py-Sketch --- README.md | 14 ++++++++++---- datetime-test.py | 11 +++++++---- display.py | 4 +++- 3 files changed, 20 insertions(+), 9 deletions(-) mode change 100644 => 100755 datetime-test.py mode change 100644 => 100755 display.py diff --git a/README.md b/README.md index e7ac45f..0965684 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ python-i2c-lcd ### Setup ``` -sudo apt-get install python-smbus i2c-tools +sudo apt-get install python3-smbus i2c-tools sudo modprobe i2c-dev sudo modprobe i2c-bcm2708 ``` @@ -15,16 +15,22 @@ add `i2c-dev` to `/etc/modules`. ### Usage ``` -python2 ./display.py line_1~line_2~line_3~line_4 +python3 ./display.py line_1~line_2~line_3~line_4 +# OR +chmod +x display.py +./display.py line_1~line2 ``` or clock demo: ``` -python2 ./datetime-test.py +python3 ./datetime-test.py +# OR +chmod +x datetime-test.py +./datetime-test.py ``` ### Based on * https://github.com/pimatic/pimatic/issues/271 -* http://www.gejanssen.com/howto/i2c_display_2004_raspberrypi/index.html \ No newline at end of file +* http://www.gejanssen.com/howto/i2c_display_2004_raspberrypi/index.html diff --git a/datetime-test.py b/datetime-test.py old mode 100644 new mode 100755 index 4508eb3..e783a62 --- a/datetime-test.py +++ b/datetime-test.py @@ -1,17 +1,20 @@ -import lcd +#!/usr/bin/env python3 + from time import time from time import sleep from datetime import datetime +import lcddriver -lcd = lcd.lcd() +lcd = lcddriver.lcd() #lcd.display_string("11111111111111111111222222222222222222223333333333333333333344444444444444444444", 1) lcd.display_string("LCD", 1) lcd.display_string("Hello World", 2) +lcd.clear() while True: dateString = datetime.now().strftime('%b %d %y') timeString = datetime.now().strftime('%H:%M:%S') - lcd.display_string(dateString, 3) - lcd.display_string(timeString, 4) + lcd.display_string(dateString, 1) + lcd.display_string(timeString, 2) sleep(1) diff --git a/display.py b/display.py old mode 100644 new mode 100755 index e1688d7..e4d621c --- a/display.py +++ b/display.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from lcddriver import lcd import sys @@ -22,4 +24,4 @@ line = line.replace('_', ' ') if len(line) > 16 : line = lines[0:16] - my_lcd.display_string(line, i+1) \ No newline at end of file + my_lcd.display_string(line, i+1)