Sunday, July 26, 2009

Parallel port programming using python

Setup parallel port in linux (Debian/Ubuntu)
You should have installed python on your distro. You must have the previlages of 'su' to do the following installation

# apt-get install python-parallel
# rmmod lp
# modprobe ppdev
# python

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


Assuming you have some basic python knowledge. If you didn't install pyhton -parallel, you can't import parallel. Now p.setData(oxFF) sets every outputs of parallel port to ON. Try different values instead of 0xFF. (To do this you require basic knowledge of hexadecimal representation of binary numbers). Try this chaser program.

x=[1,2,4,8,16,32,64,128]
while(1):
for i in x:
p.setData(0xFF)
time.sleep(2) #Good night for 2 seconds


The program will work until you force to quite python or an unexpected UPS failure. That may be funny ;-) But Intentionally did that for the program simplicity.

No Linux? Windows only? :-( Just try it out

There is nothing to do in windows. Download latest python first. Install it. Then download pyparallel for windows fron sourceforge. Install it Now everything OK. Open python either by command or open IDLE (It will be installed with python core in windows). Then type the following:

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


The example chaser program is also applicable for windows platform.

Read my post on parallel port programming in C/C++

2 comments:

Sreekar Guddeti said...

this blog is awesome. I was searching for some help regarding parallel port programming in python. thank you

Sreekar Guddeti said...

this blog is awesome. I was searching for some help regarding parallel port programming in python. thank you