Saturday, September 5, 2009

Parallel Port Monitoring Using MATLAB

MATLAB [!!Video Tutorial!!]


Hello friends , here is a small video tutorial on how to communicate to devices connected to our PCs parallel port using MATLAB programming. A large number of applications can be thought of using MATLAB as a platform in robotics. The digital bit data obtained at the parallel port can be utilized for driving DC motors or Stepper motors or other actuators.

%Code to transmit bits to the Parallel Port.
%The output1 & output2 matrix bits are transmitted sequentially.

parlport = digitalio('parallel', 'LPT1');
line = addline(parlport, 0:3, 'out');
output1 = [0 0 0 1; 0 0 1 1; 0 1 1 1; 1 1 1 1; 0 0 0 0];
output2 = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1; 0 0 0 0];
for m=1:5
for x = 1:5
pval1 = output1(x,:);
putvalue (parlport, pval1);
pause(0.3);
end
for y = 1:5
pval2 = output2(y,:);
putvalue (parlport, pval2);
pause(0.3);
end
end

"Feel free to post your queries and doubts in the tutorial, I will try to upload some more video tutorials exploring MATLAB as a useful tool in Robotics".

24 comments:

Unknown said...

Hey thats a real nice educative video . I was wondering that what would be the changes i need to incorporate in the MATLAB code wherein I would be controlling DC motor of 12 V using encoder circuit as feedback and H bridge as the driver .The matlab code will perform the PWM fuction as well, right ? I m a mechanical engineer so got to clear the basics with someone like you.
Thanks aand please try to reply me ASAP as i have a project on it :)

heloitsadi said...

Hi Utkarsh,

I am also a newbie to MATLAB, just have a basic knowledge only, as far as your Encoder feedback is concerned you can declare the data pins of parallel port connected to encoder as input and manipulate on it as per the number of pulses (means setting a counter variable or such type of stuff).

For controlling DC motor just provide 4-bit output to L293D driver and further connections to motor as per the data sheet of L293D.

PWM probably can be achieved using software control, but no idea about how exactly it can be done.

Cheers..:)

Unknown said...

Hey aditya ,
thank you very much for the information . by any chance do you know how the code can be written in MATLAB for open loop control of DC motor ( position control of motor is to be achived ) without the use of encoder . I mean i don't know how to program in MATLAB for even open loop control using parallel port. Could give me any help ???

heloitsadi said...

Actually their is nothing much to do with change in programming.. The program will remain similar.. just you havr to transmit bits to the parallel port as per the direction of motion of robot.. and if you wan't to achieve position control without using encoders, then you have to be bit mathematical...

Like calculate the circumference of the wheel of robot and it will give you distance traveled in one rotation, now calculate the time it take for the wheel to complete one rotation y the RPM specification of motor. THis way you can get numerical data. Now you can try setting the pause value acordingly.

For ex. If you wan't to move your robot 10cm. You do the necessary calculation and give the output on parallel port for forward motion and then give certain delay which is equivalent of moving the robo forward 10cm, now give the signal to stop. Means you have to do some hit & try types stuff.

Hope you are getting what I explained..
Roll back if any doubts.

Cheers,

Unknown said...

hey aditya thanks for that . i had doubts with ur code . like could send me an explanation of ur LEd lighting code explaining each line specially the following:
line = addline(parlport, 0:3, 'out');
wat does 0:3 stand for ?
then wat is the outermost for loop doing? and wat bout those inner loops ?
plz throw more light if u can .
oh yes one more thing , i tried ur code but if i change the value of 0:3 to 0:4 then the matlab gives me the error:
digitalio.digitalio
Error using ==> digitalio.digitalio
Failure to open requested data acquisition device. Class not registered.

heloitsadi said...

Hi Utkarsh, Sorry for delay in reply..

Here goes the explaination-
1. parlport = digitalio('parallel', 'LPT1'):
This line defines a variable and gives the hardware specification that the port is parallel and is named as LPT1(0x378 is its address, you can verify it from your Device manager)

2.line = addline(parlport, 0:3, 'out'):
This statement declares bits 0 to 3 of parallel port data pins as putput.

3. output1 = [0 0 0 1; 0 0 1 1; 0 1 1 1; 1 1 1 1; 0 0 0 0];output2 = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1; 0 0 0 0]
Output1 and output2 are simply two arrays in which i have chosen 5 combination of 4bits in each, you can choose any of the combination. I have chosen such that in output1 no. of LEDs on increase and finally go OFF and reverse is the case for output2.

4. for m=1:5
This is the loop which runs everythig in it 5 times.

5. for x = 1:5 Now for loop again for printing OUTPUT1, its 1 to 5 because I have 5 combination(0001, 0011, 0111, 1111, 0000) in my Output1 array.

6. pval1 = output1(x,:);
When ist time the second for loop executes it becomes output(1,:).. means it will take only 1st coloumn and all the rows, means it will send 0001 to pval1. similarly corresponding coloumn as per the value of 'x'.

7. putvalue (parlport, pval1);
This statement puts the value of pval1 on to the parlport,i.e in first case 0001 to parallel port, so it will glow LED connected to 3 and OFF the LEDs connected to 0, 1 and 2 of parallel port.

8. Similar are the case for pval2, its for another array output2.

So 2nd for loop from top is for Output1, 3rd for loop from top is for output2 and the first for loop from top is to repeat all these operations 5 times. You can change the value in this for loop to any value as per your wish.. but values of 2nd and 3rd for loop will remain fix at 1:5 because there are only 5 combinations in our output arrays Output1 and Output2. If you are giving 0:4 instead of 0:3 then you have to take arrays with combination of 5 bits.. For ex.
Output1 = [00001; 00011; 00111; 01111; 11111].
Because now you have five lines(0 to 4) waiting for data..

Jimmy said...

Hello Aditya,

your video explains very well how to send data to the parallel port and I thought it could be so easy to read from it as well.

However, even if I have created a loop in which I try to 'getvalue' from my well created digital object, I always get a response of '1', either pressing the buttons of my circuit or not. No change at all across time.

Is there something different that should someone consider when reading from the LPT1?

Thanks a lot!

heloitsadi said...

Hi Jimmy,

Please verify that the name assigned to your PCs parallel port is LPT1 not something else. You can chek it from Device manager, ports.

Unknown said...

Thanks to Aditya Sharma you explain it very well we got the idea in first reading
Najeeb Gandapur

heloitsadi said...

Its pleasure Najeeb.

Pratap Vardhan said...

Hi Aditya,

I am familiar with parallel port programming in MATLAB. Since,i am working on a laptop now which has only USBs, i need a USB-Parallel port converter. Recently i checked with local china-made product, drivers got installed and power is passing. Then i checked with "device manager" in vista>control panel , there is no LPT1 or any such port available. I even tried in MATLAB to access the port but failed. Please let me know, if MATLAB supports USB-parallel port and any reasonable and working product name for the converter.
Thanks in advance
pratapapvr@gmail.com
pratapgr8@gmail.com

sagar said...

hey adhi guess u doing good....
dude need one help actually me n my fnds are new to matlab and v need to know the detail steps for :
interfacing parallel ports settings for windows xp2 pc
actually our task is to send and receive bits using matlab functions and interface a trainer kit and give input and get o/p from LEDs

will be eagerly looking for ur kind help
thank u....
(mydreams46@gmail.com)

Rajni kant said...

hey aditya..
just guid me abt image processing through matlab,dat how its interfacing wid camera and how we use matlab in image processing. i mean to say dat ,it is a big software.how it will (matlab)works on small robot.

vinay said...

hi i am vinay doing my final year project
: speed control of dc motor using fuzzy logic in matlab; software part is over but i dont know to get the signals from matlab to my hardware is there any programming ; i want output as via parallel port any one pls pls help me sir
vinaymurugan@yahoo.co.in;
vinaymurugan49@gmail.com

Unknown said...

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

kmlrob said...

i want to make a image processing based robot.
plz help me.

vinay said...

@rajat...dude same problem is with me my device manager is also not showing LPT n showing printer support....do u have any idea why..??

Unknown said...

we dont have parallel ports in our lapy's n its very difficult to communicate via usb in MATLAB.
what's the solution ??

do we have any such usb to parallel converter which can communicate to MATLAB as parallel port??

Unknown said...

hey....i am using matlab2010 in laptop with windows 7 os....i need to use a parallel port...for that i bought a usb to parallel port converter. but windows recognized it only as printer port not as lpt. i tried with matlab but it showed the error "Error using ==> digitalio.digitalio at 115
Failure to open requested data acquisition device."
would you pls guide me?
(anoopr91@gmail.com)

Rohit said...

Sir, Please help me in interfacing parallel port with simulink for parallel communication. My email-id is rohit1101990@gmail.com Please reply.......... :)

bidyut said...

Sir,

We are doing a project speech recognition in robot based on matlab.
We are facing a problem to interface pc to Robot because Our pc does not have Parallel port, So please give us suggestion for interfacing

Anonymous said...

sir,
i need help designing a virtual oscilloscope for which i need to write a MATLAB code for interfacing the parallel port of PC. The beginning part 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.

Unknown said...

Hey Aditya,
Thank you for the informative video. I am working on a project which involves acquiring images from a line scan camera that is connected to the CPU through parallel port. The "winvideo" is for acquiring images through a usb cable. What about acquiring images through parallel port?
i eagerly look forward for your response. It's quite urgent as I have my submission deadline in a week.
Thank you!

Unknown said...

Hi Aditya,

I am familiar with parallel port programming in MATLAB. Since,i am working on a laptop now which has only USBs, i need a USB-Parallel port converter. Recently i checked with local china-made product, drivers got installed and power is passing. Then i checked with "device manager" in vista>control panel , there is no LPT1 or any such port available. I even tried in MATLAB to access the port but failed. Please let me know, if MATLAB supports USB-parallel port and any reasonable and working product name for the converter.
Thanks in advance
malikmiffz@gmail.com