
Read Arduino Through PC Printer Port
- 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
In this second test program we will again learn how to interface a PC printer port to read a DS18B20 Centigrade temperature sensor though an Arduino microcontroller. This differs in that we use PC printer 8-bit data port to control Arduino. We'll use bits D0-D2.
The purpose of these series of projects is to use the Arduino microcontroller to operate low-level electronics but use a high level language like Python to control Arduino from a common PC or Raspberry Pi.
The goal was to control and read complex sensors, operate stepper motors, etc. though the PC printer port or Raspberry Pi. This code with modifications works on Raspberry Pi and vice-versa.
I wanted to avoid the use of I2c and complex C programming with the PC. This takes advantage of my modified version of pyparallel. See Programming the PC Printer Port in Python.
Arduino is programmed in a type of low-level C and can operate a vast number of sensors and motors, but is worthless for high-level programming better done in Python.
Python is handy as it will operate much the same with any PC without getting into low-level architecture. This bridges the gap between using a nice graphical interface with python-tkinter and the electronics portion of Arduino.
The wiring diagram is shown above and was connected to an Arduino Nano - should work with any of them. The only connections used is pins 2, 3, and 4 on the DB25 connector.
The projects will get more and more complex leading the a combination Arduino with read-write capability to the PC and the PC operating a 2X16 LCD display in conjunction with Arduino. This program uses pportArduino1.ino or pportArduino2.ino.
- Arduino sketches needed by programs:
- pportArduino1.ino read only after reset.
- pportArduino2.ino reset once and multiple reads - no writes.
- 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
#!/usr/bin/env python # File pportArduinoReadbits.py # http://www.bristolwatch.com/pport/index.htm # By Lewis Loflin - lewis@bvu.net # This version use Data port bits D0-D2 # Does the same thing as pportArduinoRead.py # Data from Arduino displayed on terminal. # Read serial data from Arduino # Same as TLC548 except 16 bit # and pport must send reset to Arduino # Use reset with Arduino sketch pportArduino1.ino # Use delay after reset of 0.5 Sec. # Reset not used with Arduino sketch # pportArduino2.ino # SW1 is connected from ground to Db25 pin 10 and pulled high # by a 10k resistor. import parallel import time p = parallel.Parallel() # 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 Arduino D4 p.setInitOut(0) # Pin 16 output NC p.setSelect(0) # Pin 17 output NC # data LSB first # enable CS1 HIGH # set CLK HIGH # read data bit shift left # set CLK LOW # repeat 15 times # then once more after loop. # last bit should not be shifted. # Arduino #define CLK 6 #define CS1 5 #define dataBit 4 # Connect to Arduino CLK D6 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 # Connect to Arduino CS1 D5 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 # Connect to Arduino Reset def writeD2(bit_val): if bit_val == 1: p.setData(p.data() | 4) #set bit 1 else: # clear bit 1 p.setData(p.data() & (255 - 4)) return writeD2(0) writeD1(0) writeD0(0) #################################Arduino################## # Reset Arduino to perform whatever reading # use transistor between pport and Arduino def resetArduino(): writeD2(1) time.sleep(.001) writeD2(0) time.sleep(3) # Read Arduino # DelayT is used to pause after enable CS # for sensor to upsate. Delay should be # 0.5 Sec. for DS18B20 to cycle through. # 0.1 for everything else. def readArduino(delayT): temp = 0 writeD1(1) # enable CS time.sleep(delayT) for i in range(0,15): # loop here 7 times writeD0(1) # CLK HIGH time.sleep(.001) temp = temp + p.getInError() # get bit temp = temp << 1 # shift 1 bit left writeD0(0) # CLK LOW writeD0(1) # CLK HIGH time.sleep(.001) temp = temp + p.getInError() # get bit 8 writeD0(0) # CLK LOW writeD1(0) # CS LOW return temp ##################################################### # Print a 16-bit number (integer) in binary. # Returns string. # unlike python bin() this doesn't drop leading zeros def convBinary(value): binaryValue = 'b' for x in range(0, 16): temp = value & 0x8000 if temp == 0x8000: binaryValue += '1' else: binaryValue += '0' value = value << 1 return binaryValue #################################################### # SW1 is connected from ground to DB25 pin 10 and pulled high # by a 10k resistor. def SW1(): return p.getInAcknowledge() # check pin 10 DB25 when pressed returns 0 def degC(val): # convert value DS18B20 read return val * 0.0625 def degF(val): # convert value DS18B20 read return (val * 0.0625) * 9 / 5 + 32 print "Please wait for reading..." j = readArduino(.5) # delay .5 sec. for DS18B20 print hex(j) print bin(j) print j print degC(j), "deg. C" print degF(j), "deg. F" 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.
- 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.