Control the Parallel (or Serial) Port with Python
Sean writes "Here's a follow-up to your recent perlParallel post. It's a python module for controlling the parallel port. This module encapsulates the access for the parallel port. It provides backends for Python running on Windows and Linux. They also have a serial port controller here. Link.
Posted by Phillip Torrone |
May 9, 2005 02:56 PM
Computers |
Permalink
| Comments (3)
Recent Entries
- HOW TO - build a water mortar
- Jake's steamcar project, dashboard redo
- Build your own water quality tester
- MAKE @ Yahoo! Buzz
- Made in Japan Vol. 3
- Super Breakout version allows for competitive or collaborative gaming
- How DIYers just might revive American innovation
- Light-Field camera makes blurry images a thing of the past
- Make a pizza box solar oven
- DIY Security system calls your phone
Comments
Oldest comments listed first.
Ok, reposting.
Here's a python script that uses PySerial to interact with buttons connected to your serial port. So you can use those buttons to do whatever you'd like on your computer. The circuit is super simple, just shorts 4 of the pins to ground:
http://www.ovelha.org/pasteler0/2005/11/17/howto-external-winamp-control/
I personally find it easier to splice an old serial cable than the way he did it. Cheaper too. And I hate to admit it, but there's been a couple of times that I didn't have a continuity meter handy and I simply spliced wires and connected them randomly until I got a reaction, and I havn't fried any serial ports yet.
And it works great with those USB to serial adaptors too.
Note that there's a really good Winamp plugin on that page that also interfaces with this circuit, and in that program are instructions to connect up to 15 buttons to a single serial port, and this script can probably be easily adapted to that. Also note that the above circuit works with the excellent Windows automation program Girder.
Feel free to email wrybread@gmail dot-you-know-what with any questions.
Anyway, here's the script, which for some reason is showing up double-spaced:
import serial # This is pyserial, you need that.
import time# Adjust this for whatever number your comport is.
com_port = 1print "Attempting to open your com port..."
try:
# Initialize our com port:
buttons = serial.Serial(com_port)print "Successfully opened the com port."
print "Your com port returned the following information:\n"
print buttonsexcept:
print "Whoops, failed to initialize your com port"print "\nListening for button presses..."
# Start monitoring button presses:
while True:
#modes are CTS, DSR, RI and CD. As in getCTS, getDSR, etc.
if buttons.getCTS():
print "Button 1 pressed!"
# Do something here.if buttons.getDSR():
print "Button 2 pressed!"
# Do something here.
if buttons.getRI():
print "Button 3 pressed!"
# Do something here.
if buttons.getCD():
print "Button 4 pressed!"
# Do something here.
time.sleep(.02)And to the person wishing for PHP support, I'd highly recommend sucking it up and learning Python...
Subscribe to MAKE Magazine!
Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.
$34.95 / 1 year
(4 Quarterly Issues)
Features and more @ MAKE!
MAKE @ The NYC Toy Fair 2008 - Covering DIY!HOW TO - Build the arms of assistance.
MADE in Japan - Part I.
MADE in Japan - Part II.
MADE in Japan - Part III.
Make store - Blinky bug kit - Blink!
Make store - Loud Objects Noise Toy Kit
Makers - MAKE Flickr pool contest. Win cool stuff!
Makers - Join the MAKE Facebook page - Meet other makers.
MAKE on Twitter - Tweet! Tweet!
What you're reading in MAKE - Data!
Add MAKE to your RSS reader - Real simple.

Why advertise on MAKE?
Read what folks are saying about us!
Click here to advertise on MAKE!
Phillip Torrone
Senior Editor
Tel: 707-827-7311
Gareth Branwyn
Robot Maker
Jonah Brucker-Cohen
Researcher
Natalie Zee Drieu
Senior Editor
CRAFT
Becky Stern
Culture jammer
Collin Cunningham
Sound Maker
Marc de Vinck
CNC Maker
Current Podcast
AHAB High Altitude Ballooning - Best of Weekend Projects
mp4|mov|hd|3gp|3g2|itunes This week on Best of Weekend Projects, we look back at part two of the AHAB (High Altitude Balloon Adventure). In this epic Bre & Co. travel to Eastern Washington to launch a GPS and camera enabled balloon...
More...

