Browse files

First ugly hacks to make Adafruit_CharLCD work with my shift register

  • Loading branch information...
1 parent ed67e62 commit 0b15dbf95ba0d065f638086b4285c61dd00bb9ea @lmorchard committed May 14, 2013
Showing with 51 additions and 2 deletions.
  1. +9 −1 Adafruit_CharLCD.py
  2. +3 −1 Adafruit_CharLCD_IPclock_example.py
  3. +39 −0 ShiftOutputGPIO.py
View
10 Adafruit_CharLCD.py
@@ -7,6 +7,13 @@
#
from time import sleep
+#!/usr/bin/env python
+import time
+import RPi.GPIO as GPIO
+from ShiftOutputGPIO import ShiftOutputGPIO
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setwarnings(False)
class Adafruit_CharLCD:
@@ -254,7 +261,8 @@ def message(self, text):
if __name__ == '__main__':
- lcd = Adafruit_CharLCD()
+ shift_out = ShiftOutputGPIO()
+ lcd = Adafruit_CharLCD(pin_rs=4, pin_e=5, pins_db=[0,1,2,3], GPIO=shift_out)
lcd.clear()
lcd.message(" Adafruit 16x2\n Standard LCD")
View
4 Adafruit_CharLCD_IPclock_example.py
@@ -4,8 +4,10 @@
from subprocess import *
from time import sleep, strftime
from datetime import datetime
+from ShiftOutputGPIO import ShiftOutputGPIO
-lcd = Adafruit_CharLCD()
+shift_out = ShiftOutputGPIO()
+lcd = Adafruit_CharLCD(pin_rs=4, pin_e=5, pins_db=[0,1,2,3], GPIO=shift_out)
cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
View
39 ShiftOutputGPIO.py
@@ -0,0 +1,39 @@
+import time
+import RPi.GPIO as GPIO
+
+class ShiftOutputGPIO:
+
+ BCM = None
+ OUT = None
+
+ def __init__(self, num_channels=8, S_DS=23, S_ST=24, S_SH=25):
+
+ self.num_channels = num_channels
+ self.S_DS = S_DS
+ self.S_ST = S_ST
+ self.S_SH = S_SH
+
+ self.state = [0 for idx in range(0, self.num_channels)]
+
+ for p in (self.S_DS, self.S_ST, self.S_SH):
+ GPIO.setup(p, GPIO.OUT, initial=GPIO.LOW)
+
+ def setup(self, *args, **kwargs):
+ pass
+
+ def setmode(self, *args, **kwargs):
+ pass
+
+ def output(self, chan, state, commit=True):
+ self.state[self.num_channels - 1 - chan] = state
+ if (commit):
+ self._commit()
+
+ def _commit(self):
+ GPIO.output(self.S_ST, 0)
+ for bit in self.state:
+ GPIO.output(self.S_DS, int(bit))
+ GPIO.output(self.S_SH, 1)
+ GPIO.output(self.S_SH, 0)
+ GPIO.output(self.S_ST, 1)
+ #time.sleep(0.01)

0 comments on commit 0b15dbf

Please sign in to comment.