0

Interfacing with PC ports

Posted by SUYOG PATIL on 8:17 PM in , , ,
Many people asked me to put some Matlab interfacing with PC ports tutorials so this is it...
 

Interfacing with PC ports
MATLAB provides support to access serial port (also called as COM port) and parallel port (also called as printer port or LPT port) of a PC.
Note: If you are using a desktop PC or an old laptop, you will most probably have both, parallel and serial ports. However in newer laptops parallel port may not be available. 

Parallel Port
Parallel port has 25 pins as shown in figure below. Parallel port cables are locally available (commonly referred as printer port cables). These cables are handy to connect port pins with your circuit. Pins 2-9 are bi-directional data pins (pin 9 gives the most significant bit (MSB)), pins 10-13 and 15 are output pins (status pins), pins 1,14,16,17 are input pins (control pins), while pins 18-25 are Ground pins.









MATLAB has an adaptor to access the parallel port (similar to adaptor for image acquisition). To access the parallel port in MATLAB, define an object
>> parport= digitalio('parallel','LPT1');
You may obtain the port address using,
>> get(parport,'PortAddress')
>> daqhwinfo('parallel'); % To get data acquisition hardware information
You have to define the pins 2-9 as output pins, by using addline function
>> addline(parport, 0:7, 'out')

Now put the data which you want to output to the parallel port into a matrix; e.g.
>> dataout = logical([1 0 1 0 1 0 1 1]);
Now to output these values, use the putvalue function
>> putvalue(parport,dataout);
Alternatively, you can write the decimal equivalent of the binary data and output it.
>> data = 23;
>> putvalue(parport,data);

You can connect the pins of the parallel port to the driver IC for the left and right motors of your robot, and control the left, right, forward and backward motion of the vehicle. You will need a H-bridge for driving the motor in both clockwise and anti-clockwise directions.

Serial Port
If you have to transmit one byte of data, the serial port will transmit 8 bits as one bit at a time. The advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs 8).


Pin 3 is the Transmit (TX) pin, pin 2 is the Receive (RX) pin and pin 5 is Ground pin. Other pins are used for controlling data communication in case of a modem. For the purpose of data transmission, only the pins 3 and 5 are required.

At the receiver side, you need a voltage level converter called as RS232 IC which is a standard for serial communication. And to interpret the serial data, a microcontroller with UART (Universal asynchronous receiver transmitter) is required aboard the robot. Most of the microcontrollers like AVR ATMEGA 8, Atmel/Philips 8051 or PIC microcontrollers have a UART. The UART needs to be initialized to receive the serial data from PC.

In this case, the microcontroller is connected to the motor driver ICs which control the right and left motors. After processing the image, and deciding the motion of the robot, transmit codeword for left, right, forward and backward to the microcontroller through the serial port (say 1-Left, 2-Right, 3-Forward, 4-Backward).

MATLAB code for accessing the serial port is as follows:
>> ser= serial('COM1','BaudRate',9600,'DataBits',8);
>> fopen(ser);
To send data through the serial port, the available commands
>> fwrite (ser,1); % for left motion
>> fwrite (ser,2); % for right motion
You can close the port in case there are other applications using this port using the fclose command.
>> fclose(ser);
Microcontroller has an output port whose pins can be used to control the driver IC. Thus, microcontroller interprets the serial data from the PC and suitably controls the motors through the output pins and the motor driver.




All those who want to build Matlab controlled robotic car you can get all help and circuit diagrams here
download files here


Thank you for reading...
 






|

0 Comments

Post a Comment

Copyright © 2009 ALL ABOUT ROBOTICS!! All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.