PC printer Port Reads Arduino Sensors
This first test program we will learn how to interface a PC printer port to read a DS18B20 Centigrade temperature sensor though an Arduino microcontroller.
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.
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 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 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.
- 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
#!/usr/bin/env python # File pportArduinoRead.py # http://www.bristolwatch.com/pport/index.htm # By Lewis Loflin - lewis@bvu.net # Read serial data from Arduino # Same as TLC548 except 16 bit # # Use reset with Arduino sketch pportArduino1.ino # Reset not used with Arduino sketch # pportArduino2.ino # Reset only once for pportArduino2.ino # which will return integer from DS18B20 # temperature sensor. Will convert to F and C. # Arduino data displayed on terminal. # 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 to CLK DP6 Arduino p.setAutoFeed(0) # Pin 14 output NC p.getInError() # Pin 15 input to DATA OUT Arduino DP4 p.setInitOut(0) # Pin 16 output to CS-NOT DP5 Arduino p.setSelect(0) # Pin 17 output Arduino reset # 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 # Reset Arduino to perform whatever reading # use transistor between pport and Arduino def resetArduino(): p.setSelect(1) time.sleep(.001) p.setSelect(0) time.sleep(3) def readArduino(): temp = 0 p.setInitOut(1) # enable CS time.sleep(.001) for i in range(0,15): # loop here 7 times p.setDataStrobe(1) # CLK HIGH time.sleep(.001) temp = temp + p.getInError() # get bit temp = temp << 1 # shift 1 bit left p.setDataStrobe(0) # CLK LOW p.setDataStrobe(1) # CLK HIGH time.sleep(.001) temp = temp + p.getInError() # get bit 8 p.setDataStrobe(0) # CLK LOW p.setInitOut(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): return val * 0.0625 def degF(val): return (val * 0.0625) * 9 / 5 + 32 # Use Arduino sketch pportArduino1.ino resetArduino() print "Please wait for reading..." time.sleep(.5) j = readArduino() 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.