3

Using Python, I am trying to interface with a HD44780 16x2 LCD display and would like to save a few pins from my Pi's GPIO banks by using a 74HC595 shift register.

So far, I have managed to run the LCD display with 6 pins - using Adafruit's LCDChar Python Library - and I also managed to drive a bunch of LEDs through the 595 thanks to the wiringPi2-Python library.

I have spent many hours trying to hack the LCDChar Python Library based on some code done for a similar purpose for the Arduino but I am not getting much success. Does anyone from this fine community has something to share that would meet my purpose?

3 Answers3

2

The WiringPi2 library turns out to be an answer. It has a shift register extension that allows to easily address the 74HC595 without the need to deal with its registers and binary value shifts.

It also has an LCD extension that handles the HD44780.

Putting the two together gives something like this:

#!/usr/bin/python
from wiringpi2 import *

wiringPiSetup() #use wiringPi pin scheme

#assign values to 595's pins
pinBase = 100
RS =  pinBase + 0
E =   RS + 1
DB4 = E + 1
DB5 = DB4 + 1
DB6 = DB5 + 1
DB7 = DB6 + 1

#Pi's pin out using WiringPi's scheme
dataPin, clockPin, latchPin = 0, 1, 2

#           pin @ QA, num pins used, SER    , SRCLK   , RCLK 
sr595Setup (pinBase , 6            , dataPin, clockPin, latchPin)

# Now, let's handle the HD44780 ...
# RS, E, DB4, DB5, DB6 and DB7's signals are coming out of the 595
lcd = lcdInit (2, 16, 4, RS, E, DB4, DB5, DB6, DB7, 0,0,0,0)
lcdHome(lcd)
lcdClear(lcd)
lcdPosition(lcd, 0, 0)
lcdPuts(lcd, "oh yeah!")
lcdPosition(lcd, 0, 1)
lcdPuts(lcd, "it works!")

The Adafruit RGB LCD Plate and WiringPi page provides a similar example, but this time it shows how to drive the HD44780 with a MCP23017 I2C GPIO expander chip.

0

Can you adapt this to your situation?

G Ragib
  • 97
  • 1
  • 4
0

There are serial LCDs available from SparkFun, that allow the output using only 1 (ONE) control pin besides POWER and GND. Inexpensive and easy to use. And 5V TTL input means you may connect it directly to the Raspberry Pi and it should work just fine (or you may order 3.3V version).

lenik
  • 11,503
  • 1
  • 29
  • 37
  • I am looking for code to make the 595 drive the LCD. – Monsieur David May 21 '13 at 16:28
  • i have shown you the way to use 1 (one) single pin for LCD control. are you expecting to occupy less pins using 595? i really doubt it. – lenik May 21 '13 at 16:35
  • I have the LCD and the 595 - I would like to use components I already own. – Monsieur David May 21 '13 at 18:15
  • poor design choices might ruin your project. nonetheless, i wish you luck in your endeavour. – lenik May 22 '13 at 15:06
  • Thanks Lenik. One thing I like with the Raspberry Pi is that it is a relatively inexpensive way to experiment interfacing computer programming and electronics. – Monsieur David May 22 '13 at 18:16
  • @lenik, those serial LCDs are a lot more expensive than a regular one. Might be ok for one or two modules, but if the project is something that needs to be inexpensive there's no need to use an expensive one pin solution if two or three pins are available. – John La Rooy Aug 21 '13 at 10:26