DB25 connector pinouts.

Python PC Printer Port Controls Serial LCD Display

by Lewis Loflin

Here we've connected a 2X16 LCD display to the PC printer port. A count from 0-255 will be displayed as binary on the 8 LEDs and as decimal, octal, and hex on the LCD. The electronics works identical to earlier projects listed below that were written in C.

Here we demonstrate to output serial data to an outside device.

74164  shift regiter connected to LCD display.

Connect as serial LCD display as follows:

# Bit_out  Pin 1-2 Sn74164
# CLK  Pin 9 Sn74164 - clock bit - LOW to HIGH to LOW
# RS Pin 4 LCD  - LOW command; HIGH ASCII
# E Pin 6 LCD - clock data into LCD - HIGH to LOW to HIGH

# init i/o pins
p.setDataStrobe(0) # Pin 1 use as CLK 74164 pin 9
p.setAutoFeed(0)   # Pin 14 use as data bit for 74164 pins 1-2
p.setInitOut(1)    # Pin 16 use as E  LCD pin 6
p.setSelect(0)     # Pin 17 use as RS LCD pin 4

The program is written in Python and runs under Linux. To use this one must setup a module pyparallel. How to set this up is on my webpage Programming the PC Printer Port in Python

  
#!/usr/bin/env python
# File pportlcd.py
# http://www.bristolwatch.com/pport/index.htm
# By Lewis Loflin - lewis@bvu.net
# Must use my version of pyparallel on website for p.data().
# Connects 74165 shift register and LCD display
# Has 8 LEDs in data port Db25 pins 2-9.


# This can be done from Idle, Geany, or command line
# Set Geany to use lxterminal if available.

import parallel
import time

p = parallel.Parallel()


Line1 = 0x80  # location LCD row 0 col 0 or line 1
Line2 = 0xC0  # location LCD row 1 col 0 or line 2


# Bit_out  Pin 1-2 Sn74164
# CLK  Pin 9 Sn74164 - clock bit - LOW to HIGH to LOW
# RS Pin 4 LCD  - LOW command; HIGH ASCII
# E Pin 6 LCD - clock data into LCD - HIGH to LOW to HIGH

# init i/o pins
p.setDataStrobe(0) # Pin 1 use as CLK orange wire
p.setAutoFeed(0)   # Pin 14 use as data bit for 74164 yellow
p.setInitOut(1)    # Pin 16 use as E  brown wire
p.setSelect(0)     # Pin 17 use as RS white wire


def pulseCLK():
    p.setDataStrobe(1)
    #time.sleep(.01) 
    p.setDataStrobe(0)
    return

def pulseE():
    p.setInitOut(0)
    #time.sleep(.01)
    p.setInitOut(1)
    return

# MSB out first!
def ssrWrite(value):
    for  x in range(0,8):
        temp = value & 0x80
        if temp == 0x80:
           p.setAutoFeed(1) # set data bit HIGH
        else:
            p.setAutoFeed(0)
        pulseCLK()
        value = value << 0x01 # shift left
        time.sleep(.001)
    p.setDataStrobe(0)
    p.setAutoFeed(0)
    return 


def initLCD():
    p.setSelect(0) # RS LOW
    ssrWrite(0x38) # setup for 2 lines
    pulseE()
    ssrWrite(0x0F) # blinking cursor
    pulseE()
    clearLCD()
    Home()
    return 

def clearLCD():
    p.setSelect(0) # RS LOW
    ssrWrite(0x01) # clear
    pulseE()
    return
    
def Home():
    p.setSelect(0) # RS LOW
    ssrWrite(0x02) # home
    pulseE()
    return 
    

def gotoLocation(val):
    p.setSelect(0) # RS LOW
    if val < 0x80:
        val = 0x80
    ssrWrite(val)
    pulseE()
    return


def writeString(myString):
    i = len(myString)
    p.setSelect(1) # Pin 17 RS - HIGH is ASCII
    for  x in range(0,i):
       y = ord(myString[x])
       ssrWrite(y)
       pulseE()
    p.setSelect(0) # Pin 17 RS LOW
    return

# convert an 8-bit number to a binary string
def convBinary(value):
    binaryValue = 'b'
    for  x in range(0,8):
        temp = value & 0x80
        if temp == 0x80:
           binaryValue = binaryValue + '1'
        else:
            binaryValue = binaryValue + '0'
        value = value << 1
    return binaryValue


initLCD()



# print in binary on LCD and LEDs
print "Now counting in binary on LCD and LEDs - please wait..."
for j in range(0, 256):
    myStr1 = convBinary(j)
    writeString(myStr1)
    p.setData(j) # write to data port
    time.sleep(.1)
    Home()
    
clearLCD() # clr LCD


print

# print j in HEX, OCT, base 10
# print binary on LEDs
print "Counting int j in HEX, OCT, base 10 on LCD" 
print "and in binary on LEDs - please wait..."
for j in range(0, 256):
    p.setData(j)
    writeString('J = ' + str(j)) # base 10
    gotoLocation(Line1 + 8)
    writeString('OCT ' + oct(j)) # print octal
    gotoLocation(Line2)
    writeString('HEX ' + hex(j)) # print hex
    time.sleep(.1)
    Home()
    
p.setData(0) # LEDs all off

clearLCD() # clr LCD

gotoLocation(Line1)
writeString("Finished!")

gotoLocation(Line2)
writeString("Good by!")

print
print "Finished, good by."

exit


Download pport-1.0.iso from Sourceforge.com then burn to DVD (file size 920 meg.), insert into DVD drive and reboot. Make sure PC is set to boot from DVD ROM.

This is pre-configured by myself to use Python to control the printer port. Python can be run from IDLE or Geany.

All of my PPORT electronics projects will work without installation to a PC.

Programs can be saved to thumb drive in LIVE mode.

Projects

Below are listed a series of projects using pyparallel and electronics. Starting with routines I wrote to aid students I'd advise walking through this in sequence. Have fun and send comments and/or corrections to lewis@bvu.net.

Linux Videos

Printer Port in C


Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.