Parallel Port

Here i will deal with parapllel ports in C,vb and MATLAB 7.0

Parallel ports are the 25 pin cute things that you will find behind your computer pannel. here is a picture below to show you the pin categories. Basically they are split into three categories.The control pins,status and data pins (as shown below).

parallel port pins

Now dataports and status ports (pins actually) can be used for input and oputput data and the status are used by the computer to find out the status of an external device and thus can serve a good input port. Actually speaking mostly all these can be used for input and output but you can't use output to status pins. (*If your ports don't work just check your BIOS there will be a option to elect ports as bidirectional so just enable that option).

If you are using any os of higher than 'Me' your ports are protected for security reasons and thus you need to open it.You can get port opennig software called userport.sys . just open it and execute it and you can see it show this.

userport image

To monitor you port pin status just download a software caller parmon with which you can monitor your ports status and it looks as shown below

pram

now in the above image you can see that all data pins are LOW(GREEN) and all HIGH(RED 5v). now you can see that all of the data port are all '0' and the status pins are '1' high. Note that the control pins donot indicate the actual number in the "DEC" column in the monitor screen since they are negative logic.

Here below shows that all data pins are high, a value 255 and the next having a value254

pram pram

Start with C

in c adressing the port is very simple. just use the syntax outportb(address,value). Firstly note that the value is in hex i,e 255 is "FF" and here is how you will fiond the addess. check the 'Device manager' and click properties of 'COM1' which will show you this:

device manager
Normally we can use use '0x03FB' in plave of address. So outport(0x03FB,0xff); will output value "FF" to the data pins.of the parallel port.

To get an input from the port use : b = inportb(address) ; where bwill be a user defined variable. now this ends the discussion about C.

PORT ADDRESSING IN VB

download this DLL file and put it in the 'system' folder in your computer. now open a VB project and open a module and type in the followingin the plain module region.
Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

module

now open a form and make a command button 'command1' and a textbox 'text1' now the following will letyou outputthe value to port (NOTE IT IS IN DECIMAL VALUE).

vbOut 888,255 <– here 888 suggests Data port (890 for control) and 255 is the data [variable]=vbInp([port]) <-- here the data from specifid port will be read to the vriable.

command

That's there.. i gues you all got it.

NOW MATLAB

Now the sad part is this all will work onlt in MATLAB 7.0 of greater version. now it is very simple. the following four lines will work to give you output.

open = daqhwinfo('parallel')
DIO1 = digitalio('parallel','LPT1');
DIO2 = digitalio('parallel','LPT1');
outreg = addline(DIO1, 0:7, 0, 'out');
inreg = addline(DIO2, 0:4, 1, 'in');

outreg is the variable in which output value will be put into by MATLAB and sent to ports and inreg is port to which the input value will be saved. now the '0:7' represents 8 pins of dataport and '0:4' represents 5 pins of status port.

putvalue(DIO1.Line(2),1) puts the value to line number "2" of the DIO1 configured port and the poutput value is 1.

getvalue(OBJ) will get the input value. incase u need help for this also just hold on.. today i'm a bit too tired and i'l put it up later.

–Have a nice day controlling your Parallel Ports.!! and please give your comments

  1. nanoware
    August 16, 2006 at 9:20 am | #1

    WoW!
    thank U very mUchchchchchch
    i finally read a bit from pin data.1 :)
    again thnx
    just a problem in yr page: i cant c images
    i use firefox 1.5
    very nice site
    good luck
    bye

  2. August 16, 2006 at 12:51 pm | #2

    oh thanks for that. but i see no problems with the pictures. can u send me a screenshot of how it looks to you to my mail id. madankumar.t@gmail.com

    • Ahmed
      October 5, 2011 at 7:45 am | #3

      hi madan
      please if can send for me the way and matlab codes for doing capture image and process ii to this E-mail
      al.nadabi@hotmail.com
      thank you dear

  3. James
    September 12, 2006 at 1:09 pm | #4

    Useful site, if I am to conroll individual pins of the parallel port via Matlab does the “daqhwinfo(‘parallel’)” mean I must have the data acquisition toolbox?

  4. September 12, 2006 at 4:27 pm | #5

    yeah you’l still have to use those

  5. abd
    January 13, 2007 at 4:05 pm | #6

    hi
    how can I use the port0 of LPT port as bidirectional, i.e. as in/out, in MATLAB. I hope to get answer. thanks.
    my e-mail: nesleman4048@yahoo.com

  6. January 14, 2007 at 3:20 pm | #7

    @adb : i guess that should be done by your program on runtime. make it out when u wnaa out a value. and “in” when u expect some data from external device or something. Simultaneously biderectional i’m not sure of. sorry

  7. Asaf
    February 2, 2007 at 2:16 am | #8

    I’m trying to use the data pins to input information to my computer. I’m using matlab and when I try to read the port I can only read the las value I assigned to it. The code I’m using is


    open = daqhwinfo('parallel')
    DIO1 = digitalio('parallel','LPT1');
    inreg = addline(DIO1, 0:7, 0, 'in');
    getvalue(DIO1)

    I have all ready configured my BIOS settings but i just can’t get it to work.

    Any suggestions?

  8. haloola
    February 11, 2007 at 2:36 pm | #9

    hi
    just wantd 2 thank u on ur great work u really made my life easier
    thx again

  9. fayyaz
    February 27, 2007 at 6:53 am | #10

    hiz thts a realy a wonderful work
    it helps a lot in ma porkject…..

  10. shivesh
    March 17, 2007 at 7:20 pm | #12

    hi, thanks to provide usefull inforamation regardin PP.
    I want to aquire digital value using Parallel port, but i am getting only last value. it is possible save all descrete value and reuse it.

  11. March 18, 2007 at 1:46 am | #13

    Hey man if the time doesnt synchronise then you’l get odd values only. To help you better may i know from where are you acquiring the datas?

  12. FERI-INDONESIA
    March 30, 2007 at 1:17 am | #14

    HI..
    i have enjoyed explored programming MATLAB with PPI8255, but i confuse how to send configuration like mode, access port A,B,C. if other program like pascal, delphi, assembler. they send configuration through address 378 and 37A. i don’t how to do like that in MATLAB. i have though if port (0)/ port (1) and port(2) is adddressed to 378,379 and 37A so we can direct send configuration and data to its port. OK, hope for your helping. send your comment to my email..if you not feel weight
    [feriyonika, student at GAdjah Mada University, major Electrical Enginering.30march07]

  13. March 30, 2007 at 5:12 pm | #15

    @FERI
    Well i think you are just asking about how to address 8255 from matlab when you can just control the line pins. let me know if this is what you want to ask or anything different.

    As far as i know the lines can only be individually controlled thus might not produce the required results witha 8255. I’l like to get into more detils with this question so i’l be happy if you can get ack here and put your ideas in.

    Thanks
    Madan

  14. andres
    May 1, 2007 at 8:12 pm | #16

    I Need acces the bit5 of control buffer
    how I will do this to control the port 0 as bidireccional ?

  15. andres
    May 1, 2007 at 8:15 pm | #17

    To Asaf

    If you set the bit 5 of the control buffer by other program as vB of Labview you will reed by matlab the port 0

  16. shaktipada sarkar
    June 24, 2007 at 9:56 am | #18

    how can i write simulink output to parallel port

  17. shaktipada sarkar
    June 24, 2007 at 10:05 am | #19

    hi,thanks to providing useful information on parallel port.now i want to write simulink output to matlab.please give information how can i do it.my email id sarkar_shaktipada@yahoo.co.in

  18. NeoDeGenero
    August 1, 2007 at 1:51 am | #20

    Hi, this is great stuff.
    Although i’m stumped at trying to write a string or a character to the Parallel Port (matlab)
    Things i want to write are: eg. “F”, or more complicated “I -200 200 450 1000 54 54 68″
    Would appreciate any help with writing strings in Matlab OR C to the parallel port.

    Thanks!
    email: neo_skool@hotmail.com

  19. thammu
    August 7, 2007 at 2:06 am | #21

    My question is similar to ‘shaktipada sarkar’. Is there a way for simulink model to read and write USB port.

  20. gaurav
    August 11, 2007 at 11:01 am | #22

    hey i downloaded user port and executed too and when i start it,it shows driver not installed.may i know which driver its talking about.

  21. August 11, 2007 at 7:58 pm | #23

    Did u put the DLL file into the sys folder?

  22. abhi
    September 20, 2007 at 10:51 pm | #24

    hey dude…… fabulous work

  23. asjid ali
    September 29, 2007 at 12:05 pm | #25

    i want to control stepper motor or a relay with paralell port but data write or read must be throuh web site.i mean to say taht data should be sent from anywhere and relay that is attached a pc should be controlled.plz i am worried about it help m efor my project.

  24. October 3, 2007 at 9:46 pm | #26

    well that was my final year project.
    Hint : You can do it with php (You can call system functions from php directly)

    good luck

  25. Abdul Rahman
    November 14, 2007 at 9:13 pm | #27

    thnx man it helped me alot in my project

  26. Raymundo
    December 14, 2007 at 3:05 am | #28

    How i can send and recive 8 bits, because i use Simulink to control a system, I use a pin 2 to 9 to send y 10 to 17 to recive.

    Some people told me that I have to make a S-Function.

    Thanks for help me.

    Sorry my English is pure

  27. Alok
    December 29, 2007 at 10:02 am | #29

    Thank you very much for your suggestion.

    Its working nicely

  28. prathibha
    January 16, 2008 at 5:31 am | #30

    hi
    please can someone tell me how to set bit 5 of control register of parallel port using matlab?

  29. liyasa
    January 21, 2008 at 3:39 am | #31

    i want to store the data acquired through parallel port to a matrix. i am getting the data in a loop, but i need to store that data to a matrix and then to show that matrix as an image.
    kindly help me
    i am really stuck.

  30. January 21, 2008 at 6:18 pm | #32

    @liyasa
    wow that was a god one… but thar shud be simple if u just put some thot to it….

    Read some sinal to say u are sending a 8 bit data.. read port ten and sequentially keep saving it in the matrix…

  31. Salil Banerjee
    January 31, 2008 at 12:33 pm | #33

    Could u please tell me how can i control a parallel port using simulink.

  32. leo
    February 4, 2008 at 1:54 am | #34

    hi.. gud day.
    im want connect a LED to parallel port pin number 1, i want to control LED on/off..
    please give some tips to do that.

  33. leo
    February 4, 2008 at 1:56 am | #35

    hi.. gud day.
    i want to connect a LED to parallel port pin number 1, i want to control LED on/off..
    please give some tips to do that.

    what is the output voltage coming from parallel port?

  34. tahir
    February 6, 2008 at 6:09 am | #36

    Hello Sir,
    thanks for this trivial info. i have a problem that i want to recieve optical encoder data through parallel port and want to use it in Matlab .Length of data is more then 1 pulse (say 500 pulses per second).can you please guide me how to do it.

  35. tahir
    February 6, 2008 at 6:10 am | #37

    Hello Sir,
    thanks for this trivial info. i have a problem that i want to recieve optical encoder data through parallel port and want to use it in Matlab .Length of data is more then 1 pulse (say 500 pulses per second).can you please guide me how to do it….. Tahir

  36. gaurav rajoria
    February 6, 2008 at 10:44 am | #38

    hello to all,
    i am working on my project in MATLAB and i want to give input through parallel port, and want to use them..

    how can i do it?
    please help

  37. March 6, 2008 at 9:34 pm | #39

    please help ,i use matlab with my laptop which doesn,t have lpt port ,i got usb 2 lpt cable but windows recognise it as “usb printer support ” not as ordinary lpt port,matlab didn,t recognise any lpt port

  38. alok
    May 3, 2008 at 12:19 pm | #40

    thanks……………

  39. raghu
    May 17, 2008 at 7:35 am | #41

    how to read data lines D0-D7……?

  40. raghu
    May 19, 2008 at 7:18 am | #42

    Can i do the same with matlab 6.5 version….?

  41. raghu
    May 19, 2008 at 11:22 am | #43

    how to set the bidirectional bit in control register…i.e.how to access control register through matlab..?

  42. mamtha
    May 20, 2008 at 11:59 am | #44

    how to configure data lines of parallel port as ‘in’ and read data from it using matlab 6.5… plz reply soon….

  43. samy
    May 27, 2008 at 10:46 am | #45

    hi i have to control two stepping motor with PC via parallel port and i have the peogram source writen in boolean with C3.0. and i need the graohic software (DUALSTEP.EXE)to run my program.

  44. Stefán Þ.
    May 27, 2008 at 1:52 pm | #46

    Hi. I am trying to get information from a Pulse Oximeter through a parallel port into matlab, but I am having difficulties reading the data off it. I get values from the getvalue(obj) command but it seems to be static, id est it doesnt matter if it is pluged in or not , and it doesn’t matter if i have it in an active state. The reading is [1 1 1 1 0] for the status pins, 0 being the busy signal, and the data pins all give ones’s. Does anybody have an explaination of this?

  45. Archie rono
    June 21, 2008 at 7:04 am | #47

    Can you pls tell me the codes on how to transmit 5 volts using parallel ports/com port/usb port. thanks!

  46. Shit master
    June 25, 2008 at 4:43 pm | #48

    Wtf man! Fabulous work??? there is no fucking work here. NOTHING WORKS!!!
    DickCrunch

  47. September 9, 2008 at 8:31 am | #49

    Hi

    I have created a application that reads off a photocell sensor that is place on a race track, and records race car laptimes. The application work fine, but I have noticed that on certain desktop or laptop computer the Status pins S3, S4 and S5 are high, with out any parallel port pluged into the computer. My application reads off status pin S3 for the sensor, but doesnt work when the status pin is set high on certain computers.

    Any way I can set the status pins to be low when the application starts? And why is this happening?

    Thanks

  48. Javad Ahamad K.v
    September 22, 2008 at 11:25 am | #50

    this is very very usfull site

  49. CK PATEL
    December 3, 2008 at 6:08 pm | #51

    i want 3 or more stepper moter via lpt port interfacing in turo c coding circuit

  50. Satish Sinha
    January 10, 2009 at 11:43 pm | #52

    it’s really informative site…thanx madan!
    but plz checkout why in some pages there is no image
    i.e. the ckt diagrams don’t appear.

    bcoz of this i am not able to get the ckt of h-bridge what u gave in ur next page… plz if u can send it to my mail..

  51. rajesh
    May 26, 2009 at 6:04 am | #53

    HI
    I am allso doing proj on interfacing with matlab but i don`t no how to interfac it plz help me . i want to move the dc motor

  52. farhad
    June 11, 2009 at 11:22 am | #54

    hi
    i used the paraller port for pulse generation for driving stepper motor.but from the parralel port of pc ,the maximum sample per second is about 35HZ.now i need much more frequency than it.
    can anyone help me that how can i reach the large frequency using MATLAB(paraller or serial or USB port).

  53. PRIYA
    June 20, 2009 at 3:53 am | #55

    Please send me the matlab M-file to control the pc parallel port without using DAQ Hardware
    for parallel processing .

  54. haytham douba
    June 24, 2009 at 12:37 pm | #56

    i want to cotrol in lpt by matlab can you help me please what i do thank for you
    haytham douba

  55. Norhazwani Hanoom
    August 5, 2009 at 12:46 am | #57

    Hi there,

    I just wondering,what if I use USB parallel port, can I still use matlab to control the parallel port? thanks.

  56. Norhazwani Hanoom
    August 5, 2009 at 12:47 am | #58

    Hi there,

    I just wondering,what if I use USB parallel port, can I still use matlab to control the parallel port? thanks.
    Reply

    • August 10, 2009 at 7:13 pm | #59

      yeah you can

      • shresth
        September 21, 2009 at 9:26 am | #60

        how??
        explain further plz..

  57. Waqas Rashid
    August 23, 2009 at 4:07 pm | #61

    i want to convert the webcam video stream into frames per second,i need the code following process,please send me the code of matlab

  58. shresth
    September 20, 2009 at 11:20 am | #62

    i am using matlab 7.4 and i m not able to send data through usb 2 parallel port with my laptop.
    the laptop treats usb 2 parallel port as a printer port n not a lpt port.n i am getting this :

    open = daqhwinfo(‘parallel’)

    open =

    AdaptorDllName: [1x69 char]
    AdaptorDllVersion: ’2.10 (R2007a)’
    AdaptorName: ‘parallel’
    BoardNames: {1×0 cell}
    InstalledBoardIds: {1×0 cell}
    ObjectConstructorName: {0×3 cell}

    wich means dat it is not detecting any lpt port.
    can anyone tell me what to do to access the parallel port as earliest as possible????

    thanx in advance.
    reply 2 : shresthbhutani@gmail.com

  59. Elamaran
    November 14, 2009 at 8:09 am | #63

    hello everyone.!!
    i’m facing the same problem that mentioned above. I need to use USB to parallel port converter for my project. I need the codes for interfacing it with matlab. Can any one give your idea pls…??

  60. sameer
    December 4, 2009 at 4:23 am | #64

    It is really nice and working fine. I have rotated a unipolar stepper motor using parallel port and 74LS244, ULN2003
    IC , it is really Nice and cheap. Investment only 15 INR and done the job. Yeh Hoo!!

  61. pavan kumar
    December 26, 2009 at 8:53 am | #65

    my pc doesn,t hav a parralellel port..
    can usy..USB to parrallel port converter..??
    reply…

  62. January 7, 2010 at 5:38 pm | #66

    i dont have parallel port on my laptop but i need to control wiper motor through matlab.Can it be possible through USB. i think i need to use microcontroller between laptop and the motor.. please i need some serious help quite fast ??????????

  63. Steve Robinson
    February 2, 2010 at 2:40 pm | #67

    I also need to know how to control via parallel port? I want simulink to send data to parralet port while it is showing data graphically on the monitor too.

    steve_2000_robinson@yahoo.com

    Thanks

  64. February 13, 2010 at 9:15 am | #68

    thnx a lot for giving me this information i was wory about interfacing but now i got some idea.

  65. September 5, 2010 at 2:15 pm | #69

    hey dude,
    i am working on hand tracking system can u help me out in it.
    how to calculate the centroid of the hand movement in frony of cam.??????
    it’ll be really kind of you if help me out in this case

  66. September 5, 2010 at 2:16 pm | #70

    hey dude,
    i am working on hand tracking system can u help me out in it.
    how to calculate the centroid of the hand movement in frony of cam.??????
    it’ll be really kind of you if help me out in this case……..plssssssssss do it as early as possible

  67. Rao
    October 6, 2010 at 12:16 am | #71

    Hello!
    I am working with PC using XP operating system.
    I want to use the DATA PORT of LPT1 as Bi-directional in MATLAB
    Please tell me what to do?
    Rao

  68. mohamed
    October 7, 2010 at 4:14 am | #72

    thanks for your help

  69. poo
    October 16, 2010 at 10:35 am | #73

    If change Parallel Port to USB port (web cam )
    How will I do ?
    please help me
    Thank you very much

  70. nassiri
    December 25, 2010 at 11:13 am | #74

    i write all of command to sent data on lpt1 port but i havent voltage on pins i think this port should be close how i can open ports (in matlab)
    please send your answer to my email

  71. kalsoom maai
    January 28, 2011 at 11:56 am | #75

    kuch ata bhi hy tum logo ko!!!!!!!!!!!!
    search karne betho tou aagy ye aa jaty hain besharm ,nae ata tou atleast hmara tou time waste mat kiya kro,mehrbani hogi !

  72. hasan
    March 11, 2011 at 11:19 am | #76

    i want program to interface LCD.in this program i want send data to LCD
    kindly help me

  73. jhn
    April 14, 2011 at 6:43 am | #77

    dai overa peter vidatheenga da…very bad tutorial..study more n then publish

  74. Ahmed
    October 5, 2011 at 7:47 am | #78

    please I need matlab code for capture image and process it

  75. Ahmed
    October 5, 2011 at 7:48 am | #79

    if any one could help please contact with me in this E-mail
    al.nadabi@hotmail.com

  76. December 4, 2011 at 10:15 pm | #80

    hi, that’s a respectable flier. There is any mistakes but the water is here.

  77. June 3, 2012 at 6:28 am | #81

    pretty beneficial stuff, in general I imagine this is worthy of a book mark, many thanks

  78. Muhammed
    August 27, 2012 at 3:27 pm | #82

    Thx alot

  79. Kevin
    November 8, 2012 at 7:18 am | #83

    Can you please add how to create a pulse or a clock from the parallel port using matlab?

  80. Rashi Tandon
    March 8, 2014 at 5:57 pm | #84

    can someone please help me out in writing a MATLAB code for interfacing parallel port of PC. The coding will be to check the control register 037a and check if its direction pin is high. if no, then configure it in the EPP mode and check gain or else open files corresponding to each 8 input channels.

  1. March 23, 2007 at 1:27 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: