From b77736a27659339420da11b286dabadc4ae9772a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 17 Sep 2013 17:53:29 +0200 Subject: [PATCH 1/5] Cleanup script and testing multiple lines. --- .../Adafruit_CharLCD_IPclock_example.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py index d3f6958f..667ab832 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -1,24 +1,26 @@ #!/usr/bin/python from Adafruit_CharLCD import Adafruit_CharLCD -from subprocess import * -from time import sleep, strftime +from subprocess import Popen, PIPE +from time import sleep from datetime import datetime lcd = Adafruit_CharLCD() cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" -lcd.begin(16,1) +lcd.begin(16, 3) + def run_cmd(cmd): - p = Popen(cmd, shell=True, stdout=PIPE) - output = p.communicate()[0] - return output + p = Popen(cmd, shell=True, stdout=PIPE) + output = p.communicate()[0] + return output while 1: - lcd.clear() - ipaddr = run_cmd(cmd) - lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) - lcd.message('IP %s' % ( ipaddr ) ) - sleep(2) + lcd.clear() + ipaddr = run_cmd(cmd) + lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) + lcd.message('IP %s' % (ipaddr)) + lcd.message('Hello') + sleep(2) From f0f7687f00d1f01053edb7a9eae41703ac249c66 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 17 Sep 2013 18:05:48 +0200 Subject: [PATCH 2/5] Raspberry pi fixes --- Adafruit_CharLCD/Adafruit_CharLCD.py | 14 +++++++------- .../Adafruit_CharLCD_IPclock_example.py | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD.py b/Adafruit_CharLCD/Adafruit_CharLCD.py index 22060c94..3649d9fe 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD.py @@ -54,7 +54,7 @@ class Adafruit_CharLCD: - def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None): + def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 27, 22], GPIO = None): # Emulate the old behavior of using RPi.GPIO if we haven't been given # an explicit GPIO interface to use if not GPIO: @@ -101,7 +101,7 @@ def home(self): self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero self.delayMicroseconds(3000) # this command takes a long time! - + def clear(self): @@ -113,13 +113,13 @@ def setCursor(self, col, row): self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ] - if ( row > self.numlines ): + if ( row > self.numlines ): row = self.numlines - 1 # we count rows starting w/0 self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row])) - def noDisplay(self): + def noDisplay(self): """ Turn the display off (quickly) """ self.displaycontrol &= ~self.LCD_DISPLAYON @@ -193,7 +193,7 @@ def autoscroll(self): self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - def noAutoscroll(self): + def noAutoscroll(self): """ This will 'left justify' text from the cursor """ self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT @@ -235,9 +235,9 @@ def delayMicroseconds(self, microseconds): def pulseEnable(self): self.GPIO.output(self.pin_e, False) - self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns + self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns self.GPIO.output(self.pin_e, True) - self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns + self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns self.GPIO.output(self.pin_e, False) self.delayMicroseconds(1) # commands need > 37us to settle diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py index 667ab832..3375dde0 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -9,7 +9,7 @@ cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" -lcd.begin(16, 3) +lcd.begin(16, 4) def run_cmd(cmd): @@ -23,4 +23,5 @@ def run_cmd(cmd): lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) lcd.message('IP %s' % (ipaddr)) lcd.message('Hello') + lcd.message('World') sleep(2) From f2dcbc35e90dbc566c4da3ed473c5bbeadbabb5f Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 17 Sep 2013 18:08:00 +0200 Subject: [PATCH 3/5] Add newline --- Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py index 3375dde0..a88e7f92 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -21,7 +21,7 @@ def run_cmd(cmd): lcd.clear() ipaddr = run_cmd(cmd) lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) - lcd.message('IP %s' % (ipaddr)) - lcd.message('Hello') + lcd.message('IP %s\n' % (ipaddr)) + lcd.message('Hello\n') lcd.message('World') sleep(2) From 72e19014a1eeb8ba4cd22312067e676be80ee67d Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 17 Sep 2013 18:11:03 +0200 Subject: [PATCH 4/5] Use home instead of clear --- Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py index a88e7f92..7b9cfeab 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -18,7 +18,7 @@ def run_cmd(cmd): return output while 1: - lcd.clear() + lcd.home() ipaddr = run_cmd(cmd) lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) lcd.message('IP %s\n' % (ipaddr)) From f5b41a3e8e8d6a2c0921a987e41f63e45ea84c39 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 17 Sep 2013 18:12:06 +0200 Subject: [PATCH 5/5] Simplify script --- Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py index 7b9cfeab..8ed8d2ab 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -22,6 +22,4 @@ def run_cmd(cmd): ipaddr = run_cmd(cmd) lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) lcd.message('IP %s\n' % (ipaddr)) - lcd.message('Hello\n') - lcd.message('World') - sleep(2) + sleep(1)