Additional Commands Python Py-Parallel Programming
Documentation lists only 8 commands (below) that are limited. I went into the file parallelppdev.py and found several additional commands to read the status of the four output pins and commands to turn the data port on/off, and read the data port latches. They were commented out, I commented them back in and are now available.
The documentation talks about some additional software I can't find to allow one to access the individual data port bits instead of writing just a byte at a time. The extra commands made it easy to add that feature in my programs. Being able to read the state of the data port made this easy to control individual devices attached to it.
The bit operations in pportbits.py can be imported or simply copy-paste to a new program.
Note: "Level" is "1" or "0".
setData(value)
"""Apply the given byte to the data pins of the parallel port. Pins 2-9"""
# write the 4 output (control) pins
setDataStrobe(level) # Set the "data strobe" line to the given state. Pin 1
setAutoFeed(level) # Set "auto feed" line to given state. Pin 14
setInitOut(level) # Set "initialize" line to given state. Pin (16) reset
setSelect(level) # Sets the state of the SelectIn output (pin 17)
# read the 5 input (status) pins
getInError() # Returns the level on the nFault pin (15)
getInSelected() # Read level of "select" line. pin (13)
getInPaperOut() # Read level of "paper out" line. Pin (12)
getInBusy() # Returns the level on the Busy pin (11)
getInAcknowledge() # Read level of "Acknowledge" line. Pin (10)
# below was commented back in on the parallelppdev.py file:
# read the level on 4 output (control) pins and return the state of the pin:
strobe()
"""Returns the state of the nStrobe output (pin 1)"""
autoFd()
"""Returns the state of the nAutoFd output (pin 14)"""
init() """Returns the state of the nInit output (pin 16)"""
selectIn()
"""Returns the state of the nSelectIn output (pin 17)"""
# use with data port
data()
"""Returns value of the data bus line drivers (pins 2-9)"""
setDataDir(level)
"""1 Activates or 0 deactivates the data bus line drivers (pins 2-9)"""
dataDir()
"""Returns true if the data bus line drivers are on (pins 2-9)"""
For working examples of below see Controlling Data Bits on the PC Parallel Port
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 pportbits.py # http://www.bristolwatch.com/pport/index.htm # By Lewis Loflin - lewis@bvu.net # Example code to turn ON-OFF individual bits on PC # printer port Db25 pins 2-9. # Must use my version of pyparallel on website for p.data(). # Bitwise AND is used to clear a bit while bitwise OR used to set bit. import parallel p = parallel.Parallel() 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 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 def writeD2(bit_val): if bit_val == 1: p.setData(p.data() | 4) #set bit 2 else: # clear bit 2 p.setData(p.data() & (255 - 4)) return def writeD3(bit_val): if bit_val == 1: p.setData(p.data() | 8) #set bit 3 else: # clear bit 3 p.setData(p.data() & (255 - 8)) return def writeD4(bit_val): if bit_val == 1: p.setData(p.data() | 16) #set bit 4 else: # clear bit 4 p.setData(p.data() & (255 - 16)) return def writeD5(bit_val): if bit_val == 1: p.setData(p.data() | 32) #set bit 5 else: # clear bit 5 p.setData(p.data() & (255 - 32)) return def writeD6(bit_val): if bit_val == 1: p.setData(p.data() | 64) #set bit 6 else: # clear bit 6 p.setData(p.data() & (255 - 64)) return def writeD7(bit_val): if bit_val == 1: p.setData(p.data() | 128) #set bit 7 else: # clear bit 7 p.setData(p.data() & (255 - 128)) return 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.
- Introduction to Python Bitwise Operations
- Python Bitwise Operations by Example
- Using the PC Printer Port series:
- Programming the PC Printer Port in Python
- Additional Commands for Py-Parallel
- Controlling Data Bits on the PC Parallel Port
- Connecting Switches to the PC Printer Port with Python
- Reading an Analog Voltage Through the PC Printer Port Part 1
- Reading an Analog Voltage Through the PC Printer Port Part 2
- Controlling a Serial LCD Display on a PC Printer Port with Python
- Serial ADC and LCD Display with PC Printer Port with Python
- Controlling MAX7219 LED Display with PC Printer Port with Python
- MAX7219 8-Digit LED Display and Serial ADC in Python
- Project pages:
- Part 1: Read Arduino with PC Printer Port
- Part 2: Better way to Read Arduino Through the PC Printer Port
- Part 3: Read-Write an Arduino Through a PC Printer Port
- Part 4: Control LCD Display and Arduino from the PC Printer Port
- Arduino sketches needed by programs:
- pportArduino1.ino read only after reset.
- pportArduino2.ino reset once and multiple reads.
- pportArduino3.ino reset once read write Arduino infinite times - multiple commands.
- Related Raspberry Pi projects:
- Connect Serial LCD to Raspberry Pi
- Serial Read from Arduino to Raspberry Pi
- Arduino Raspberry Pi Interface with LCD Display
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
Printer Port in C
- Exploring Digital Computer Electronics
- Hardware Review Connecting PC Parallel Ports
- Operation TB6600 Stepper Controller with PC Parallel Port
- Build or Buy Parallel Port Breakout Board?
- Build Serial HD44780 LCD Display Connect to Parallel Port
- Motherboards
- Presario 1999 CM1001 Gaming Computer Salvage
- Live Test 2002 VIA EPIA-800 Mini ITX Motherboard
- Salvage, Test 2012 AAEON EMB-B75A Industrial Motherboard
- Web Master
- Gen. Electronics
- YouTube Channel
- Arduino Projects
- Raspberry Pi & Linux
- PIC18F2550 in C
- PIC16F628A Assembly
- PICAXE Projects
Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.