DB25 connector pinouts.

Printer Port Python Controls TLC548 Serial ADC Operates LCD Display

by Lewis Loflin

Here we read the TLC548 serial analog to digital converter then send data for display on a serial LCD display. Here we demonstrate a serial read of one device and a serial write of another. This combines two earlier lessons.

Because the TLC548 analog to digital converter is controlled by two data port pins (D0, D1) we display the binary values on the LCD display.

TLC548 ADC pinout

Connect the ADC as follows:

# Connect to TLC548 CS-NOT pin 5 to Db25 pin 3 D1
# Connect to TLC548 CLK pin 7 to Db25 pin 2 D0
# Connect TLC548 Pin 6 DATA OUT to Db25 pin 15

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 pportlcdADC.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().

# This combines two earlier modules
# pportlcd.py and pporttlc548bits.py
# Program reads value from ADC and 
# displays on line 1 of LCD display.

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


'''
; Pins on the TLC548 8-bit ADC:
; 1 -> Ref + -> connect to Vcc
; 2 -> analog in
; 3 -> Ref - -> connect to GND
; 4 -> GND
; 5 -> CS-NOT -> chip select active LOW
; 6 -> DATA OUT
; 7 -> CLK
; 8 -> Vcc
'''

# see pporttlc548bits.py

# Connect to TLC548 CLK pin 7 to Db25 pin 2
def writeD0(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 1) # set bit 0
    else: # clear bit 0
        p.setData(p.data() & (255 - 1))
    return

writeD0(0) # set TLC548 CLK pin 7 LOW

# Connect to TLC548 CS-NOT pin 5 to Db25 pin 3
def writeD1(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 2) # set bit 1
    else: # clear bit 1
        p.setData(p.data() & (255 - 2))
    return

writeD1(1) # set TLC548 CS-NOT pin 5 HIGH 

# data LSB first
# enable TLC548 CS-NOT LOW
# set CLK HIGH
# read data bit shift left
# set CLK LOW


def readADC():
        temp = 0
        writeD1(0) # enable CS-NOT LOW
        # time.sleep(.01) # use for fact PCs
        for i in range(0,7): # loop here 7 times
                writeD0(1) # CLK HIGH
                temp = temp + p.getInError() # get bit
                temp = temp << 1 # shift 1 bit left
                writeD0(0) # CLK LOW
        writeD0(1) # CLK HIGH
        temp = temp + p.getInError() # get bit 8 
        writeD0(0) # CLK LOW
        writeD1(1) # CS-NOT HIGH 
        return temp


initLCD()

Home()

gotoLocation(Line1)
writeString('ADC value = ')

def Sw1():
	return p.getInAcknowledge()  
	# check pin 10 Db25 when pressed returns 0

while Sw1(): # exit when Sw1 pushed
    adcValue = readADC()
    gotoLocation(Line1 + 12)
    writeString(str(adcValue))
    time.sleep(.3)
    gotoLocation(Line1 + 12)
    writeString('   ')
    
exit



Linux Videos

Live Linux Distro for Using Printer Port with Electronics
Using the powerful Rox-Filer system in Linux
Use FEH under Linux for a Wallpaper Setter
How to create Symbolic links in Linux

Printer Port Interfacing Videos:
Connect Electronics to PC printer Port with Python
Setup PC Printer Port with Python-Linux
Use PC Printer Port to Read Analog Voltage


Read-Write Arduino ADC PWN with Printer Port
Printer Port to Serial LCD Display
Connect Arduino to PC Printer Port for advanced control

Projects


Loading

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.

 


donate