DB25 connector pinouts.

Reading an Analog Voltage Through the PC Printer Port Part 2

by Lewis Loflin

Here we simply altered the electrical connections for two of the pins in the TLC548 ADC to free up pins to connect a serial LCD display. This also demonstrates how to manipulate individual bits on the 8-bit data port.

See Reading an Analog Voltage Through the PC Printer Port Part 1

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

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 pporttlc548bits.py
# http://www.bristolwatch.com/pport/index.htm
# By Lewis Loflin - lewis@bvu.net
# Read serial ADC TLC548 and send value to terminal. 
# Connecting the TLC548 to the data port pins D0 and D1.
# Program halts when Sw1 is pressed.
# Sw1 is connected from ground to Db25 pin 10 and pulled high
# by a 10k resistor.

# Because two individual port bites used to control ADC
# they can't be used to display binary.
# This frees up pins 1 and 16 for use with LCD circuit
# with pportlcdADC.py

                              
import parallel
import time

p = parallel.Parallel()

'''
; 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
'''

# init i/o pins
p.setDataStrobe(0) # Pin 1 output NC
p.setAutoFeed(0)   # Pin 14 output NC
p.getInError()	   # Pin 15 input to DATA OUT TLC548
p.setInitOut(1)    # Pin 16 output NC
p.setSelect(0)     # Pin 17 output NC


# Connect to TLC548 CLK pin 7 to Db25 pin 2 D0
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 D1
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)
        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


# convert a 8-bit number (integer) to a binary. 
# Returns string.
# unlike python bin() this doesn't drop leading zeros
def convBinary(value):
    binaryValue = 'b'
    for  x in range(0, 8):
        temp = value & 0x80
        if temp == 0x80:
           binaryValue += '1'
        else:
            binaryValue += '0'
        value = value << 1
    return binaryValue
    

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

# Sw1 is connected from ground to Db25 pin 10 and pulled high
# by a 10k resistor.
# When Sw1 pressed program exits.	
while Sw1():
        val = readADC()
        time.sleep(.1)
        print "Reading =", convBinary(val), " ", hex(val)
 
        
p.setData(0) # LEDs off

print
print "Exit now."      
        
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.