Anda di halaman 1dari 55

MINOR PROJECT REPORT

ON

AIR GESTURE CONTROLLED ROVER (AGCRov)


Integrationof TI MSP430 MCU with MATLAB via Real Time Image Processing Submitted in partial fulfilment of the requirementfor the award of degree of Bachelor of Technology in

ELECTRONICS & COMMUNICATION Under the Sincere Supervision of


MR. MUKESH SAHU MR. KALYAN SINGH

Submitted by:DASHMEET KAUR(10413202810) NAMRATA (12513202810) ARNAV MENDIRATTA (13013202810) DAMANJEET SINGH MAAN (15213202810)

Guru Tegh Bahadur Institute of Technology G-8 Area, Rajouri Garden Affiliated to Guru Gobind Singh Indraprastha University, Dwarka New Delhi Batch 2010 2014

DECLARATION
We hereby declare that all work presented in the dissertation entitled AIR GESTURE CONTROLLED ROVER in the partial fulfilment of requirement for the award of the degree of Bachelor of Technology in Electronics and Communication, Guru Tegh Bahadur Institute of Technology, affiliated to Guru Gobind singh Indraprasth University is an authentic record of our own work carried out under the guidance of our mentor, Mr. Mukesh Sahu and Mr. Kalyan Singh.

Date:

DASHMEET KAUR (10413202810)

NAMRATA (12513202810)

ARNAV MENDIRATTA (13013202810)

DAMANJEET SINGH MAAN (15213202810)

CERTIFICATE

This is to certify that the report entitled AIR GESTURE CONTROLLED ROVER submitted by Dashmeet Kaur (10413202810), Namrata (12513202810), Arnav Mendiratta (13013202810), Damanjeet Singh Maan (15213202810) in the partial fulfilment of the requirement for the award of the degree of Bachelor of Technology in Electronics and Communications, Guru Tegh Bahadur Institute of Technology, is the record of students own work carried out by them under my supervision.The matter embodied in this report is original and has not been submitted for the award of any degree.

Date:

Mr. Vaneet Singh (Head Of Department, Electronics and Communication)

Ms. Parul Dawar (Project Coordinator,ECE)

Mr. Kalyan Singh (Project Mentor)

Ms. Shivani Duggal (Project Coordinator,ECE)

Mr. Mukesh Sahu (Project Mentor)

Mr. Amrish Maggo (Project Coordinator,ECE)

ACKNOWLEDGEMENT
It is a pleasure to acknowledge many people who knowingly and unwittingly helped us to complete our report. First of all we thank God for all the blessings, which carried us through all these days. We are particularly indebted to our college, Guru Tegh Bahadur Institute of Technology which inculcated in us, utmost respect for human values and groomed us in the field of software Technology to take on the challenges of competitive world.We would like to express our regards to our Mentors, Mr.Mukesh Sahu and Mr.Kalyan Singh for their constant encouragement and support. We would also like to express our immense gratitude towards them for providing the invaluable knowledge, time & guidance during the completion of this report.

Mr.Mukesh Sahu

Mr.Kalyan Singh

CONTENTS 1. About SOFTWARE


1.1 MATLAB R2010a(version 7.10) 1.1.1 What does MATLAB stand for? 1.1.2 Getting acquainted with MATLAB environment 1.1.3 Digital Image Processing in MATLAB 1.1.4 The process 1.1.5 Reading and displaying images 1.1.6 Making Mfile and function 1.1.7 Removing noise 1.1.8 Working in real time 1.1.9 Graphical User Interface 1.1.10Serial Communication in MATLAB 1.2 IAR EMBEDDED WORKBENCH 1.2.1 IAR Embedded Workbench Features 1.2.2 IAR Workbench IDE 1.2.3 An Extensible and Modular Environment 1.2.4 Project Management Features

3
3 3 3 5 7 7 8 11 13 15 18 20 20 20 20 20

2. About HARDWARE
2.1 MSPEXP430G2 2.1.1 Features 2.1.2 MSP430 Architecture 2.1.3 Pin Description and Terminal Functions 2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit (USART) Communication Interface 2.2 L293D Motor Control H-Bridge IC 2.3 MAX232 Serial Communication IC 2.4 USB to Serial Convertor 2.5 Serial Port 2.6 Webcam

22
22 23 24 24 27 32 34 37 38 40

3. Source Code
3.1 For MATLAB 3.2 For IAR Embedded Workbench

41
41 44

4. Conclusion 5. References

48 49

AIR GESTURE CONTROLLED ROVER (AGCRov)

LIST OF FIGURES
Fig 1: MATLAB Welcome Screen Fig 2: MATLAB Tool Box Showing current directory where files are being saved Fig 3: MATLAB Help Fig 4: MATLAB Command Window Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image Fig 6: Process Overview Fig 7: A test program in MATLAB Fig 8(a): Sample Image for detection Fig 8(b): Green Color detected in sample image Filteration Fig 9: A sample image for Filteration Fig 9(a): Output of sample image when the program is executed Fig 9(b): Filtered image Fig 9(c): Filtered image Fig 10: Snapshot of MATLAB window showing Camera Specifications Fig 11: GUIDE Quick Start Box Fig 12: Explanation of layout of the GUI Template Fig 13: Using Push Button in GUI Fig 14: The program for Push Buttons created in GUI Fig 15: TI MSP430G2 Launchpad Fig 16: TI MSP430G2x53 Architecture Block Diagram Fig 17: Pin Summary for 20 pin MSP430 Devices Fig 18(a): Connecting UART Fig 18(b): UART Bits Fig 19: The concept of H-Bridge Fig 20: A complete Schematic for L293D IC Fig 21: MAX232 Driver/Receiver Fig 22: MAX232(A) DIP Package Fig 23: DB9 Male Connector Fig 24: RS232 Connections Fig 25: Screenshot of Device Manager showing Serial Port detected at COM1 Fig 26: Screenshot of GUI in working project Fig 27: Air Gesture Controlled Rover 3 4 4 5 6 7 8 9 10 10 11 12 12 13 16 16 17 17 22 24 24 28 28 32 33 34 35 38 39 39 45 48

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

AIR GESTURE CONTROLLED ROVER (AGCRov)

ABSTRACT
This project consists of a PC, a microcontroller that collects the data from the PC through MATLAB and control the robot to move in different directions. The robot is fully controlled by the PC and the commands from the PC are received by the microcontroller using UART peripheral of microcontroller. Image processing is generated using MATLAB (MATLAB R2010a version is used). For image processing, the webcam captures the image and the image is viewed over the screen. The information from image is manipulated; the data is transmitted from PC to microcontroller through serial interfacing. The robot's hardware is a simple drive using two 200RPM DC gear motors mounted on a metal chassis with a front castor wheel. On the back motors, plastic wheels are mounted. The motor to drive the circuit uses L293D IC which has H bridge circuit to move the robot.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

AIR GESTURE CONTROLLED ROVER (AGCRov) 1. ABOUT THE SOFTWARE


1.1 MATLAB This version was released in 5th March 2010 and is known as MATLAB 7.10, release name MATLAB R2010a. The version is compatible with the Intel 32-bit microprocessor and for Mac. 1.1.1 What does MATLAB stand for? MATLAB stands for MATrix LABoratory. Hence, as the name suggests, here one can play around with matrices. Hence, an image (or any other data like sound, etc.) can be converted to a matrix and then various operations can be performed on it to get the desired results and values. Image processing is quite a vast field to deal with. User can identify colors, intensity, edges, texture or pattern in an image. In this tutorial, we would be restricting ourselves to detecting colors (using RGB values) only. 1.1.2 Getting acquainted with MATLAB environment Following is a screenshot of the MATLAB interface. MATLAB offers an easy to use interface with four main parts seen below.

Fig 1: MATLAB Welcome Screen

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

AIR GESTURE CONTROLLED ROVER (AGCRov)


There are 4 main windows: Command window: This is the main window where user write the commands, as well as see the outputs. In other words, here is user's interaction with the software. Command History: As the name suggests, it shows the list of the commands recently used in chronological order. Hence, user can double click on a command to execute it again. Current directory: It is the default directory (folder) for saving user's files. All the files which user make (like m-files, as discussed later) are saved here and can be accessed from here directly. The location of the current directory is shown in the toolbar at the top. User can change it by changing the address here.

Fig 2: MATLAB Tool Box Showing current directory where files are being saved

Workspace: It displays the list of the variables defined by you in the current session of MATLAB. The Menu bar and Toolbar: The toolbar has buttons for common operations like cut, copy, paste, undo, redo. The most important button here is the HELP button. It opens the MATLAB help window which has looks somewhat like this:

Fig 3: MATLAB Help

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

User can get the details of any MATLAB command/function here and many demos of some commonly used applications. Locate the four tabs: Contents, Index, Search Results and Demos on the left. User will then get the complete details of the function like its use, syntax, as well as few examples on how to use it.

AIR GESTURE CONTROLLED ROVER (AGCRov)


Now once we are done with knowing the essential features of MATLAB, lets start typing something in the command window, say: a=5 and press enter.

Fig 4: MATLAB Command Window

1.1.3 DIGITAL IMAGE PROCESSING IN MATLAB


Important terms and types of Images Pixel: Pixels are the building blocks of an image. In other words, a pixel is the smallest possible image that can be depicted on the screen. Binary Image: An image that consists of only black and white pixels. Gray scale Image: It contains intensity values ranging from a minimum (depicting absolute black) to a maximum (depicting absolute white) and in between varying shades of gray. Typically, this range is between 0 and 255. *Note: In daily language what we refer to as black-and-white (as in old photos) are actually grayscale. Color Image: Such an image is composed of the three primary colors, Red, Green and Blue, hence also called an RGB image. RGB value: All colors which we see around us can be made by adding red, blue and green components in varying proportions. Hence, any color of the world can uniquely be described by its RGB value which stands for red, blue and green values. This triplet has each value ranging from 0 to255 with 0 meaning no component of that particular color and 255 meaning full component. For example, pure red color has RGB value [255, 0, 0], pure white has [255, 255, 255], pure black has [0, 0, 0] and has RGB value [55, 162, 170].
Page Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 5(a)

Fig 5(b)

Fig 5(c) Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image

Representation of an Image in MATLAB An image in MATLAB is stored as a 2D matrix (of size mxmxn) where each element of the matrix represents the intensity of light/color of that particular pixel. Hence, for a binary image, the value of each element of the matrix is either 0 or 1 and for a grayscale image each value lies between 0 and 255. A color image is stored as an mxnx3 matrix where each element is the RGB value of that particular pixel (hence its a 3D matrix). It can be considered as three 2D matrices for red, green and blue intensities.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

AIR GESTURE CONTROLLED ROVER (AGCRov) 1.1.4 THE PROCESS


The basic overview of the process is follows: Firstly the user points in front of the camera. In order to be detected, the users fingers are covered by a color-coded band (red in our case). Now the software program detects the users finger in the form of a colored band by the specific RGB values.

Fig 6: Process Overview

Once detected, the program replaces the picture of the band with a centroid. This enables to treat it as a point sourced object. Now, the MATLAB program will detect the movement of this centroid for a subsequent number of frames. This number of frames to be captured can be changed according to the processor speed and camera quality (We have used 10 frames per trigger).

1.1.5 Reading and displaying Images


imread(): To read an image and store in a matrix. Syntax: IM=imread(filename) where IM is a matrix. If the file is in the current directory (as described above), then you only need to write the filename, else you need to write the complete path. Filename should be with extension (.jpg, .bmp,..). There are some default images of MATLAB like peppers.png, cameraman.tif, etc.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

AIR GESTURE CONTROLLED ROVER (AGCRov)


User can try reading them as >>im=iread('peppers.png'); It is always advised to use a semi-colon (;) at the end of the statement of reading an image. Imshow(): Displays the image. Syntax: imshow(filename) or imshow(im) Example, >>imshow('cameraman.tif); 1.1.6 Making M-files and functions M-file It is a provision in MATLAB where user can execute multiple commands using a single statement. Here the group of commands is stored as a MATLAB file (extension .m). Go to File->New->Blank M-file MATLAB editor window opens where user can write the statements which user want to execute and save the file.

Fig 7: A test program in MATLAB

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

Here we have saved the m-file by the name test.m. Now as you type >>test in MATLAB command window, all the above commands will execute.

AIR GESTURE CONTROLLED ROVER (AGCRov)


Comments: As we have comments in C/C++/ Java using double slash (//), in MATLAB we use symbol % to write comments, i.e., statements that are not considered for execution. You can see comments in green in the snapshot above. Functions Functions are written to organize the code efficiently and make debugging easier. The set of statements within a function can be executed as and when required by just calling it, thereby avoiding repetitions. The data which is needed within the function can be passed as arguments and then the required values can be returned. User can return any no. of values and they can be matrices also. A function is saved as an m-file with the same name as the name if the function. For Example, the following function takes the input as a coloured image and returns a binary image where the green pixels have been replaced as white, rest are black and also returns the total number of green pixels.

Fig 8(a): Sample Image for detection So, you first read the image and then call the function by typing in the command window >> I=imread('shapes.bmp'); >>[img, n]=green(I); >>n n= 28753 >>imshow(img);
Page Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 8(b): Green Color detected in sample image As you can see, this is a binary image with white pixels at those coordinates which were green in input image. Consider the following picture, which is processed using Matlab commands given as follows:

Fig 9: A sample image for Filteration

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

So, we use the same function with the main conditional statement changed as: functionbw=red(im) [m,n,t]=size(im); bw=zeros(m,n); for i=1:m for j=1:n

10

AIR GESTURE CONTROLLED ROVER (AGCRov)


if(im(i,j,1)>150 &&im(i,j,2)<50 &&im(i,j,3)<50) %Specifying range for red bw(i,j)=1; end end end User can define more specific range as per their requirement. Now when we see the output image, it looks like

Fig 9(a): Output of sample image when the program is executed

1.1.7 Removing Noise The binary image obtained above has quite a lot of noise. There is a need to smoothen the edges, remove the tiny dots scattered here and there so that at last you have some countable number of objects to work upon. There are several functions available in MATLAB to remove noise in an Image. Some of them are (bw is the above binary image): bwconncomp(BW): This returns the connected components CC found in BW. The binary image BW can have any dimension. CC is a structure with four fields. bwconncomp uses a default connectivity of 8 for two dimensions and 26 for three dimensions CC = bwconncomp(BW,conn) specifies the desired connectivity for the connected components. conn can have 4, 8, 6,18 or 26 value.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

11

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 9(b): Filtered Image

imfill(): Remove holes from the image Holes are background pixels surrounded by foreground (image) pixels. >>bw=imfill(bw,'holes'); >>imshow(bw);

Fig 9 (c): Filtered Image Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

12

AIR GESTURE CONTROLLED ROVER (AGCRov)

The use of making a binary file: In most of problem statements of robotics based on image processing, we are required to find the centroid, area, and no. of objects of a particular colour. MATLAB has in-built functions for these tasks which operate on binary images only. Hence we create binary images corresponding to different colours. For example, in the problem statement Brooklyn Builder of Techkriti10, the image from the top (overhead camera) looks somewhat like (again its an ideal image; the real one will be far different and full of noise) 1.1.8 Working in Real Time Getting Hardware information Till now we have been working on images already saved on our computer. But in actual practice, we need to work in real time, i.e., we need to take images continuously from the current environment using a webcam and then process them. Hence, the Image Acquisition toolbox of MATLAB provides support in this regard. To start with working in real time, you must have a functional USB webcam connected to your PC and its driver installed. MATLAB has built-in adaptors for accessing these devices. An adaptor is a software that MATLAB uses to communicate with an image acquisition device. You can check if the support is available for your camera in MATLAB by typing the following: >>imaqhwinfo % stands for image acquisition hardware info >>cam=imaqhwinfo; >>cam.InstalledAdaptors

Fig 10: Snapshot of MATLAB window showing Camera Specifications Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

13

AIR GESTURE CONTROLLED ROVER (AGCRov)

To get more information about the device, type >>dev_info = imaqhwinfo('winvideo',1)

Fig 10(a): Snapshot of MATLAB window showing Camera Specifications

Most probably you would have 'winvideo' installed and use that. If it is not available, use whichever adapter is shown by imaqhwinfo If you are using a laptop, you may also have a webcam in it. So note down the DeviceName shown as above. If it is not the USB webcam, then probably DeviceID = 2 should work. Hence, type >>dev_info = imaqhwinfo('winvideo',2) *Note:From now onwards, I will refer Adapter by winvideo and DeviceID by 1. You must check yourself what is available on your system and change the commands described further accordingly. Note down the supported formats by your camera as >>dev_info = imaqhwinfo('winvideo',1); >>dev_info.SupportedFormats

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

Fig 10(b): Supported video formats for installed Camera

14

AIR GESTURE CONTROLLED ROVER (AGCRov)

There are 5 supported formats in my camera. The numbers (160x120, 176x144.) denote the size of the image to be captured by the camera. Previewing video One can preview the video captured by the camera by defining an object (say by the name vid) and associate it with the device. >>vid=videoinput('winvideo',1, 'YUY2_160x120') or >>vid=videoinput('winvideo',1, 'RGB24_160x120') % depends on availability It should give information somewhat like this

Fig 10(c): Snapshot of MATLAB window showing a summary of Input Video

1.1.9 Graphical user interface


GUIDE initiates the GUI design environment (GUIDE) tools that allows user to create or edit GUIs interactively Starting GUIDE Start GUIDE by typing guide at the MATLAB command prompt. This command displays the GUIDE Quick Start dialog box, as shown in the following figure.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

15

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 11: GUIDE Quick Start Box

From the GUIDE Quick Start dialog box, one can perform the following tasks: Create a new GUI from one of the GUIDE templatesprebuilt GUIs that you can modify for your own purposes. Open an existing GUI.

The Layout Editor When you open a GUI in GUIDE, it is displayed in the Layout Editor, which is the control panel for all of the GUIDE tools. The following figure shows the Layout Editor with a blank GUI template.

Fig 12: Explanation of layout of the GUI Template Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

16

AIR GESTURE CONTROLLED ROVER (AGCRov)

User can lay out their GUI by dragging components, such as panels, push buttons, pop-up menus, or axes, from the component palette, at the left side of the Layout Editor, into the layout area. For example, if user drag three push buttons into the layout area, it might look like this. The illustration also shows how the GUIDE tool palette looks when user set a preference to show component names, as described above. User can also use the Layout Editor (along with the Toolbar Editor and Icon Editor) to create menus and toolbars, create and modify tool icons, and set basic properties of the GUI components.

Fig 13: Using Push Button in GUI

And there is an auto generated program is like the following:

Fig 14: The program for Push Buttons created in GUI Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

17

AIR GESTURE CONTROLLED ROVER (AGCRov)

1.1.10 SERIAL COMMUNICATION IN MATLAB


Serial Interface (RS-232) and MATLAB Many devices and instruments connect to a computer through a serial interface. User can communicate with any device or instrument that has a serial interface directly from MATLAB and Simulink with Instrument Control Toolbox. The toolbox provides the tools that let user communicate with, configure and transfer data to or from their serial device without writing code. Usercan generate MATLAB code for their serial device that they can reuse later to communicate with their device or develop graphical applications. User can also communicate with their serial device using MATLAB scripts or create their own software drivers and encapsulate low-level serial commands into higher level commands that are easier to access. Always Set: User always have to set this to match what is specified in the documentation that came with their device. BaudRate Always Check: The defaults here are usually OK, but user should check that they match whatever is specified in the device documentation. Terminator (sometimes have to change) 'LF' is linefeed, 'CR' is carrage return, etc FlowControl (defaults usually OK) Parity (defaults usually OK) DataBits (defaults usually OK) ByteOrder (more on this later)

Good Idea To Set: User's device will work without setting these but user can set these to make their life easy later. Tag:The tag is like giving the serial port object a nickname.If have a few different serial ports open this a good way to keep track of them.Example, serialPort is configured to talk with a garmin GPS. set(serialPort, 'tag', 'GarminGPS') TimeOut: If user try to read data from the serial port and there is no data in the buffer matlab will keep trying to read for "Timeout" seconds (default 10 sec): get(serialPort, 'Timeout') ans = 10
Page

This might really slow down the code. There are ways around this, but if there is no data there user probably don't want to sit there for 10 seconds, so consider making it smaller. On the other hand, it does
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

18

AIR GESTURE CONTROLLED ROVER (AGCRov)


take some time for messages to pass over the wire, so setting it to zero means user will probably miss a lot of messages. InputBufferSize: This specifies how long the buffer is.The default is 512 bytes. That might not be long enough for the messages. Especially if user think the sensor will be streaming data back more frequently than they plan on reading the buffer. Remember if the sensor tries to send data and the buffer is full it will discard some old data and it will be gone forever. On the other hand, having unnecessarily large buffer can be cumbersome.

Closing Serial Port Objects Concepts When user is done with a serial port object it doesn't go away. Also, closing it, deleting it from memory and clearing it from the workspace are three separate actions. Example Code For technical reasons user have to use this syntax to properly get rid of it: delete(serialPort_new) clearserialPort_new

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

19

AIR GESTURE CONTROLLED ROVER (AGCRov) 1.2 IAR Embedded Workbench


IAR Embedded Workbench is a development environment that includes a C/C++ compiler and debugger and supports 30 different processor families. 1.2.1 The IAR Embedded Workbench Features The IDE is the framework where all necessary tools are seamlessly integrated: The highly optimizing IAR C/C++ Compiler The IAR Assembler The versatile IAR XLINK Linker The IAR XAR Library Builder and the IAR XLIB Librarian A powerful editor A project manager A command line build utility IAR C-SPY Debugger, a state-of-the-art high-level language debugger. IAR Embedded Workbench is available for many microprocessors and microcontrollers in the 8-, 16-, and 32-bit segments, allowing user to stay within a well-known development environment also for the next project. It provides an easy-to-learn and highly efficient development environment with maximum code inheritance capabilities, comprehensive and specific target support. IAR Embedded Workbench promotes a useful working methodology, and you can reduce your development time significantly by using the IAR Systems tools. We call this concept Different Architectures. One Solution. If user want detailed information about supported target processors, contact the software distributor or IAR Systems representative, or visit the IAR Systems web site www.iar.com for information about recent product releases. 1.2.2 IAR Embedded Workbench IDE for MSP430 The IAR XLINK Linker can produce many output formats, allowing for debugging on most third-party emulators.Support for RTOS-aware debugging and high-level debugging of state machines canalso be added to the product. The compiler, assembler, and linker can also be run from a command line environment,if user want to use them as external tools in an already established project environment.The IDE is a flexible integrated development environment, allowing user to developapplications for a variety of target processors. It provides a convenient Windowsinterface for rapid development and debugging. 1.2.3 AN EXTENSIBLE AND MODULAR ENVIRONMENT Although the IDE provides all the features required for a successful project, we also recognize the need to integrate other tools. Therefore the IDE is easily adapted to work. The IAR Embedded Workbench IDE. 1.2.4 Project management FEATURES The IDE comes with functions that will help user to stay in control of all projectmodules, for example, C or C++ source code files, assembler files, include files, andother related modules. User create workspaces and let them contain one or severalprojects. Files can be grouped, and options can be set on all levelsproject, group, orfile. Changes are tracked so that a request for rebuild will retranslate all
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

20

AIR GESTURE CONTROLLED ROVER (AGCRov)


requiredmodules, making sure that no executable files contain out-of-date modules. This list shows some additional features: Project templates to create a project that can be built and executed out of the box fora smooth development startup Hierarchical project representation Source browser with a hierarchical symbol presentation Options can be set globally, on groups of source files, or on individual source files The Make command automatically detects changes and performs only the requiredoperations Text-based project files Custom Build utility to expand the standard tool chain in an easy way Command line build with the project file as input.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

21

AIR GESTURE CONTROLLED ROVER (AGCRov) 2. ABOUT THE HARDWARE


2.1 MSP-EXP430G2 The Texas Instruments MSP430 family of ultra-low-power microcontrollers consists of several devices featuring different sets of peripherals targeted for various applications. The architecture, combined with five low-power modes, is optimized to achieve extended battery life in portable measurement applications. The device features a powerful 16-bit RISC CPU, 16-bit registers, and constant generators that contribute to maximum code efficiency. The digitally controlled oscillator (DCO) allows wake-up from low-power modes to active mode in less than 1 s. The MSP430G2x13 and MSP430G2x53 series are ultra-low-power mixed signal microcontrollers with built-in 16-bit timers, up to 24 I/O capacitive-touch enabled pins, a versatile analog comparator, and built-in communication capability using the universal serial communication interface. In addition the MSP430G2x53 family members have a 10-bit analog-to-digital (A/D) converter. Typical applications include low-cost sensor systems that capture analog signals, convert them to digital values, and then process the data for display or for transmission to a host system.

Fig 15: TI MSP430G2 Launchpad

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

22

AIR GESTURE CONTROLLED ROVER (AGCRov)


2.1.1 Features Low Supply-Voltage Range: 1.8 V to 3.6 V Ultra-Low Power Consumption Standby Mode: 0.5 A Off Mode (RAM Retention): 0.1 A Five Power-Saving Modes Ultra-Fast Wake-Up From Standby Mode in Less Than 1 s 16-Bit RISC Architecture, 62.5-ns Instruction Cycle Time Basic Clock Module Configurations Internal Frequencies up to 16 MHz With Four Calibrated Frequency Internal Very-Low-Power Low-Frequency (LF) Oscillator 32-kHz Crystal External Digital Clock Source Two 16-Bit Timer_A with three Capture/Compare Registers Up to 24 Capacitive-Touch Enabled I/O Pins Universal Serial Communication Interface (USCI) Enhanced UART Supporting Auto Baud rate Detection (LIN) Active Mode: 230 A at 1 MHz, 2.2 V On-Chip Comparator for Analog Signal Compare Function or Slope Analog-to-Digital (A/D) Conversion 10-Bit 200-ksps Analog-to-Digital (A/D) Converter With Internal Reference, Sample-and-Hold, and Autoscan.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

23

AIR GESTURE CONTROLLED ROVER (AGCRov)


2.1.2 MSP430 Architecture

Fig 16: TI MSP430G2x53 Architecture Block Diagram

2.1.3 Pin Description Terminal Functions

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

Fig 17: Pin Summary for 20 pin MSP430 Devices

24

AIR GESTURE CONTROLLED ROVER (AGCRov)


Pin Description Table PIN NO. 1 2 TERMINAL DVCC
P1.0/ TA0CLK/ ACLK/

I/O NA

DESCRIPTION

General-purpose digital I/O pin

A0 CA0 3
P1.1/ TA0.0/ UCA0RXD/

I/O

Timer0_A, clock signal TACLK input ADC10 analog input A0(1)


ACLK signal output

Comparator_A+, CA0 input


General-purpose digital I/O pin Timer0_A,capture:CCI0Ainput,compare:Out0output/BSL transmit USCI_A0 UART mode: receive data input

I/O

UCA0SOMI/ A1/ CA1 4


P1.2/ TA0.1

USCI_A0 SPI mode: slave data out/master in ADC10 analog input A1(1) Comparator_A+, CA1 input I/O
General-purpose digital I/O pin Timer0_A, capture: CCI1A input, compare: Out1 output

UCA0TXD/ UCA0SIMO/ A2/ CA2 5


P1.3/

USCI_A0 UART mode: transmit data output USCI_A0 SPI mode: slave data in/master out ADC10 analog input A2(1) Comparator_A+, CA2 input
General-purpose digital I/O pin

ADC10CLK/ A3/ VREF-/VEREF-/ CA3/ CAOUT 6


P1.4/

I/O

ADC10, conversion clock output(1) ADC10 analog input A3(1) ADC10 negative reference voltage (1) Comparator_A+, CA3 input Comparator_A+, output
General-purpose digital I/O pin

SMCLK/ UCB0STE/ UCA0CLK/ A4/ VREF+/VEREF+/ CA4/ TCK

I/O

SMCLK signal output USCI_B0 slave transmit enable USCI_A0 clock input/output ADC10 analog input A4(1) ADC10 positive reference voltage(1) Comparator_A+, CA4 input JTAG test clock, input terminal for device programming and test

P1.5/

General-purpose digital I/O pin

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

25

AIR GESTURE CONTROLLED ROVER (AGCRov)


TA0.0/ UCB0CLK/ UCA0STE/ A5/ CA5/ TMS I/O Timer0_A, compare: Out0 output / BSL receive USCI_B0 clock input/output USCI_A0 slave transmit enable ADC10 analog input A5(1) Comparator_A+, CA5 input JTAG test mode select, input terminal for device programming and test

P2.0/

General-purpose digital I/O pin I/O

TA1.0

Timer1_A, capture: CCI0A input, compare: Out0 output

P2.1/ I/O

General-purpose digital I/O pin

TA1.1

Timer1_A, capture: CCI1A input, compare: Out1 output


General-purpose digital I/O pin

10

P2.2/ I/O

TA1.1 11
P2.3/ I/O

Timer1_A, capture: CCI1B input, compare: Out1 output


General-purpose digital I/O pin

TA1.0

Timer1_A, capture: CCI0B input, compare: Out0 output


General-purpose digital I/O pin

12 13

P2.4/

TA1.2
P2.5/

I/O

Timer1_A, capture: CCI2A input, compare: Out2 output


General-purpose digital I/O pin

TA1.2

I/O

Timer1_A, capture: CCI2B input, compare: Out2 output

14

P1.6/

General-purpose digital I/O pin I/O

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

TA0.1 A6/ CA6/ UCB0SOMI/ UCB0SCL/

Timer0_A, compare: Out1 output ADC10 analog input A6(1) Comparator_A+, CA6 input USCI_B0 SPI mode: slave out master in USCI_B0 I2C mode: SCL I2C clock JTAG test data input or test clock input during

26

AIR GESTURE CONTROLLED ROVER (AGCRov)


TDI/TCLK programming and test

15

P1.7/

General-purpose digital I/O pin

A7/ CA7/ CAOUT/ UCB0SIMO/ UCB0SDA/ TDO/TDI

I/O

ADC10 analog input A7(1) Comparator_A+, CA7 input Comparator_A+, output USCI_B0 SPI mode: slave in master out USCI_B0 I2C mode: SDA I2C data JTAG test data output terminal or test data input during programming

16

RST/

Reset

NMI/ SBWTDIO I 17
TEST/

Nonmaskable interrupt input Spy-Bi-Wire test data input/output during programming and test
Selects test mode for JTAG pins on Port 1.

SBWTCK 18
XOUT/

Spy-Bi-Wire test clock input during programming and test


Output terminal of crystal oscillator(3)

P2.7 19
XIN/

I/O

General-purpose digital I/O pin


Input terminal of crystal oscillator

P2.6/ TA0.1 20
DVSS

I/O
NA

General-purpose digital I/O pin Timer0_A, compare: Out1 output


Ground reference

2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit(USART) Communication Interface The universal synchronous/asynchronous receive/transmit communicationinterface of the MSP430 family can operate in two different modes: synchronousand asynchronous.MSP430 has Universal Serial Communication Interface (USCI) Module also for serial communication. Depending on derivative of the MSP430 we can either use USCI or USART and enable one of the modes of operation such as UART, SPI, I2C, etc. Using UART UART is simple to connect and it uses 2 lines: TX (Transmit) and RX (Receive). No clock isrequired because its asynchronous. RS232 is a common connection between PC and devices, and it can be easily converted to RS232 using a level converter. Another popular solution is to connect the UART of the MSP430 to a USB to UART converter when interfaced to another module that uses UART, you will need to cross connect the lines.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

27

AIR GESTURE CONTROLLED ROVER (AGCRov)


The TX of one device will connect to the RX of another device, while the RX will be connected to the TX of the second device.

Fig18(a): Connecting UART

Fig18(b):UART Bits UART sends bit serially, one bit after the other, as opposed to parallel. However user dont usually send individual bits because of the fact that they convey little information by themselves. Rather, the UART uses a buffer that is one byte (8 bits) long to which information is written. On a deeper level, the module sends more than just the byte a user places in the buffer. UART typically sends a start bit, seven or eight data bits, an even/odd/no parity bit, an address bit (address-bit mode), and one or two stop bits. The extra bits depend on the configuration of the UART module, but the most common configuration is 8 data bits, one stop bit and no parity. Extra bits that are sent are ultimately discarded and not stored at the destination buffer. The result of the parity check is however available. Figure 18(b) shows the bit arrangement in the MSP430s UART Module. Configuring the UART Before user can use the UART successfully to send data, both the host computer and the UART Module must be configured. Because the communication is asynchronous, if the two are not configured correctly then errors will occur because the interpretation of the timing of the bits will be off. To better explain how to configure the UART module, the following code is used as an example.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

28

AIR GESTURE CONTROLLED ROVER (AGCRov)


Listing: Configuring UART 1 P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD 2 ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD 3 UCTL0 |= CHAR; // 8-bit character 4 UTCTL0 |= SSEL0; // UCLK = ACLK = 32.768kHz 5 UBR00 = 0x03; // 32.768kHz/9600 - 3.41 6 UBR10 = 0x00; 7 UMCTL0 = 0x4a; // Modulation 8 UCTL0 &= SWRST; // Initialize USART state machine 9 IE1 |= URXIE0 + UTXIE0; // Enable USART0 RX/TX interrupt The code above demonstrates that the following steps are needed: 1. Select the I/O pins for UART 2. Enable UART TX, RX, or Both 3. Select the character format - 7 or 8 bits 4. Source the UART Module with a clock of a certain frequency 5. Set the baud generator correctly so as to get a correct baud rate from the clock sourced 6. Enable the UART module state machine 7. Enable Interrupts if required Enabling UART RX and TX The UART module is very flexible. It can control the RX and TX functionalities individually.In this case we are enabling both. To do this the following code is used: ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD Of course, for different UART modules we will need to use different register settings. Selecting Clock Just like most modules in the MSP430, a clock must be chosen for the UART, and this is arguably the most critical task. Remember that the UART module sends bits every x amount of time. The timing for the bits is determined from the baud rate, which is derived from a division of the clock time. User will assume the clock has already stabilized and is working. Also, it should operate at a specific frequency. In general, the clock frequency dictates the maximum baud rate allowed. ACLK, which is the auxiliary clock and is usually 32kHz or less (although in some cases it can be sourced from an external high frequency crystal). This means that in reality, and to keep errors low, user should select a baud rate of 9600 baud or less. Higher baud rates require a higher clock and this is normally sourced from SMCLK and MCLK, which themselves are sourced by the internal DCO or an external high frequency crystal. A crystal is always preferable because it has much better frequency stability and would almost guarantee better performance as far as error rates. Its only drawback is the added price and space requirements. To select the clock source for BRCLK user need to set the SSELx bits (bits 5 and 4) of the UTCTL1 (for USART1) or UTCTL0 (for USART0).Bits 5 and 4 will cause the following selection: Binary 00 01 10 11 Hex 0x00 0x10 0x20 0x30 Define Clock Source SSEL0 UCLKI SSEL1 ACLK SSEL2 SMCLK SSEL3 SMCLK

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

29

AIR GESTURE CONTROLLED ROVER (AGCRov)


The define Column indicates an easy to use definitions defined in the header file msp430x16x.hthat simplifies reading the code. To select the 32kHz ACLK source we simply do: UTCTL0 |= SSEL0; // UCLK = ACLK = 32.768kHz If we wanted to select SMCLK we could do: UTCTL0 |= SSEL1; // UCLK = ACLK = 32.768kHz UTCTL0 |= SSEL1; // UCLK = SMCLK Setting the Baud Rate Generator The baud rate we get is derived from the clock sourced to the UART module. Standard baud rates are used and include: 1200 2400 9600 19200 57600 115200 230400 Using desired baud rate and clock rate we can calculate the divisors required to generate the baud rate. These calculators use the same methodology that will be presented. Given a baud rate b = 9600 and a clock speed c = 32768 we have: divisor = c/b = 32768/9600 = 3.413 The integer part of this divisor is easily implementable and you can see so in the code: UBR00 = 0x03; // 32.768kHz/9600 -> 3 integer part 16-bit Integer divisors are possible because there are two registers, UBR00 and UBR01, both 8-bit. UBR00 contains the upper byte while UBR00 contains the lower byte (lower 8 bits). In this case 3 is not greater than 255 so that we place 0x00 in the upper byte and 3 (or its hex equivalent 0x03) on the lower byte. However, we need to get as close as possible to 3.413 or else our baudrate will be off and we would like it to be as close as possible. In cases where there is no fractional part we ideally dont need to deal with it, but it occurs in most every case because the clock used is never perfect. Using the modulation register we can approximate the fractional part of 3.413 to some degree of accuracy. To calculate the number of bits we need to set in the modulation register we multiply the fractional part by 8: 8 * 0:413 = 3:304 Rounding gives us 3, so that tell us 3 of the 8 bits in the modulation register need to be set. To determine which bits to turn on we to successively multiply the fractional part: The important thing to note is whether, for every addition of one to the multiplying factor, wejump to the next integer. For example, multiplying by 2 resulted in 0.826 which has an integer of 0. Multiplying by 3 means 1.239 which has an integer part of 1. Because they are not the same we say that we set it that bit because it carried. On the other hand from 3 to 4 we still have 1 as the integer part, so we dont set. Notice that we have a total of 8 multiplications so we can set the 8 bits of the modulation register. Starting from the multiplication by 2, we consider the first bit to be 0 because multiplication by 1 previously has the same integer as multiplying by 2. The second multiplication by 3 changes the integer part so we do set that one. The multiplication by 4 doesnt so we dont set that bit. Note that when we first multiplied 8 * 0.413 = 3.304 we said that we needed to have 3 bits set (1) when rounding down in the register and from the table it is apparent that we have obtained only 3 bits set. All we need to do is to consider that we start with the bits, from the bottom or top. The answer is that the bit

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

30

AIR GESTURE CONTROLLED ROVER (AGCRov)


for which we multiplied by 2 is the Least Significant i.e. we start from the bottom of the table and go up, resulting with the following: 01001010 = 0x4A Enabling the Module Once all the settings are complete, we can enable the module as follows: UCTL0 &= SWRST; // Initialize USART state machine Enabling Interrupts Although it is possible to perform UART operations like as receiving bytes using polling techniques, it is most commonly done using interrupts and these must be enabled. The UART reset state does not have to be enabled to turn them on or off. This can be done as follows: IE1 |= URXIE0 + UTXIE0; // Enable USART0 RX/TX interrupt Both interrupts are enabled. Sending and Receiving Information with the UART Now that the UART is correctly configured and the hardware is set (including the PC software), we can send data using the UART. This is in fact very simple for single bytes. Each UART module contains two buffers, a receive buffer and a transmit buffer. For the sending buffer, the user places data (a byte in this case) and the module sends it by serializing it and sending the appropriate bits. For the receive buffer it is the opposite, the bits are deserialized and converted into a byte. To send a byte of data we simple put it in TXBUF0 or TXBUF1: TXBUF0 = 0x41; TXBUF1 = 0x41; The UART module takes the data put into the buffer and sends it automatically without any further intervention. Sending multiple bytes isnt much harder. We simply have to ensure that the sending of the previous byte was finalized before putting new information in the buffer, and this is done by checking the appropriate flag: while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready? The MSP430 will keep executing the while loop (do nothing because of the colon) until the sending flag has been cleared. Since the UART buffer is one byte(when it is configured to use 8 bits), we can send any number from 0 to 255, or 0x00 to 0xFF. A major use of sending data is to send readable information. ASCII is a standard encoding supported by terminal emulators and the C compilers for the MSP430, which allows us to send readable characters. In this case ASCII maps a byte with a specific value to a specific character. For example, the lowercase a corresponds to 0x61 while b corresponds to 0x62. It is not necessary to learn the ASCII table. Any compiler will automatically replace a with the corresponding number without the user needing to explicitly specify that value.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

31

AIR GESTURE CONTROLLED ROVER (AGCRov) 2.2 L293D Motor Control H-Bridge IC
The first thing comes to mind when making a robot is making the robot move on the ground. And there are always two options in front of the designer whether to use a DC motor or a stepper motor. When it comes to speed, weight, size, cost... DC motors are always preferred over stepper motors. There are many things which user can do with your DC motor when interfaced with a microcontroller. For example user can control the speed of motor, user can control the direction of rotation, user can also do encoding of the rotation made by DC motor i.e. keeping track of how many turns are made by their motors etc. So one can see DC motors are no less than a stepper motor. Usually H-bridge is preferred way of interfacing a DC motor. These days many IC manufacturers have H-bridge motor drivers available in the market like L293D is most used H-Bridge driver IC. H-bridge can also be made with the help of transistors and MOSFETs etc. rather of being cheap, they only increase the size of the design board, which is sometimes not required so using a small 16 pin IC is preferred for this purpose. The name "H-Bridge" is derived from the actual shape of the switching circuit which control the motion of the motor. It is also known as "Full Bridge". Basically there are four switching elements in the Hbridge as shown in the figure below.

Fig 19: The concept of H-Bridge

In figure above there are four switching elements named as "High side left", "High side right", "Low side right", "Low side left". When these switches are turned on in pairs motor changes its direction accor15dingly. Like, if we switch on High side left and Low side right then motor rotate in forward directio16n, as current flows from Power supply through the motor coil goes to ground via switch low side right.17 Similarly, when we switch on low side left and high side right, the current flows in opposite direction and motor rotates in backward direction.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

32

AIR GESTURE CONTROLLED ROVER (AGCRov)


A simple schematic for interfacing a DC motor using L293D is shown below

Fig 20: A complete Schematic for L293D IC

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

33

AIR GESTURE CONTROLLED ROVER (AGCRov) 2.3 MAX232 Serial Communication IC


Max232 is primary used for people building electronics with an rs232 interface. Serial RS-232 (V.24) communication works with voltages (between -15V ... -3V are used to transmit a binary '1' and +3V ... +15V to transmit a binary '0') which are not compatible with today's computer logic voltages. On the other hand, classic TTL computer logic operates between 0V ... +5V (roughly 0V ... +0.8V referred to as low for binary '0', +2V ... +5V for high binary '1' ). Modern low-power logic operates in the range of 0V ... +3.3V or even lower. So, the maximum RS-232 signal levels are far too high for today's computer logic electronics, and the negative RS-232 voltage can't be grokked at all by the computer logic. Therefore, to receive serial data from an RS-232 interface the voltage has to be reduced, and the 0 and 1 voltage levels inverted. In the other direction (sending data from some logic over RS-232) the low logic voltage has to be "bumped up", and a negative voltage has to be generated, too. RS-232 TTL Logic -----------------------------------------------15V ... -3V <-> +2V ... +5V <-> 1 +3V ... +15V <-> 0V ... +0.8 <-> 0

Fig 21: MAX232 Driver/Receiver

The MAX232 from Maxim was the first IC which in one package contains the necessary drivers (two) and receivers (also two), to adapt the RS-232 signal voltage levels to TTL logic. It became popular, because it just needs one voltage (+5V) and generates the necessary RS-232 voltage levels (approx. 10V and +10V) internally. This greatly simplified the design of circuitry. Circuitry designers no longer need to design and build a power supply with three voltages (e.g. -12V, +5V, and +12V), but could just provide one +5V power supply, e.g. with the help of a simple 78x05 voltage regulator. The MAX232 has a successor, the MAX232A. The ICs are almost identical, however, the MAX232A is much more often used (and easier to get) than the original MAX232, and the MAX232A only needs external capacitors 1/10th thecapacity of what the original MAX232 needs. MAX232(A) is just a driver/receiver. It does not generate the necessary RS-232 sequence of marks and spaces with the right timing, it does not decode the RS-232 signal, it does not provide a serial/parallel conversion. All it does is to convert signal voltage levels. Generating serial data with the right timing and decoding serial data has to be done by additional circuitry, e.g. by a 16550 UART or one of these small micro controllers.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

34

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 22: MAX232(A) DIP Package

Pin Description Table for MAX232(A) DIP Package Pin Layout PIN Name Purpose 1 2 3 4 5 6 7 8 C1+ V+ C1C2+ C2V+ connector for capacitor C1 output of voltage pump - connector for capacitor C1 + connector for capacitor C2 - connector for capacitor C2 output of voltage pump / inverter Signal Voltage Capacitor Value MAX232 Capacitor Value MAX232A 100nF 100nF to VCC 100nF 100nF 100nF 100nF to GND

capacitor should stand at 1F least 16V +10V, capacitor should stand at least 16V 1F to VCC

capacitor should stand at 1F least 16V capacitor should stand at 1F least 16V capacitor should stand at 1F least 16V -10V, capacitor should stand at least 16V RS-232 RS-232 1F to GND

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

R2in

Receiver 2 input

35

T2out Driver 2 output

AIR GESTURE CONTROLLED ROVER (AGCRov)


9 10 11 12 13 14 15 16 R2out Receiver 2 output T2in T1in Driver 2 input Driver 1 input TTL TTL TTL TTL RS-232 RS-232 0V +5V 1F to VCC see above 100nF to VCC see above

R1out Receiver 1 output R1in Receiver 1 input

T1out Driver 1 output GND VCC Ground Power supply

V+(2) is also connected to VCC via a capacitor (C3). V-(6) is connected to GND via a capacitor (C4). And GND(15) and VCC(16) are also connected by a capacitor (C5), as close as possible to the pins. A Typical Application The MAX232(A) has two receivers (converts from RS-232 to TTL voltage levels) and two drivers (converts from TTL logic to RS-232 voltage levels). This means only two of the RS-232 signals can be converted in each direction. Typically a pair of a driver/receiver of the MAX232 is used for

TX and RX MAX232 to RS232 DB9 Connection as a DCE MAX232 Pin No. MAX232 Pin Name Signal Voltage DB9 Pin 7 8 9 10 11 12 13 14 15 T2out R2in R2out T2in T1in R1out R1in T1out GND RTS CTS CTS RTS TX RX TX RX GND RS-232 8 RS-232 7 TTL TTL TTL TTL n/a n/a n/a n/a

RS-232 3 RS-232 2 0 5

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

36

AIR GESTURE CONTROLLED ROVER (AGCRov)

In addition one can directly wire DTR (DB9 pin 4) to DSR (DB9 pin 6) without going through any circuitry. This gives automatic (brain dead) DSR acknowledgment of an incoming DTR signal. Sometimes pin 6 of the MAX232 is hard wired to DCD (DB9 pin 1). This is not recommended. Pin 6 is the raw output of the voltage pump and inverter for the -10V voltage. Drawing currents from the pin leads to a rapid breakdown of the voltage, and as a consequence to a breakdown of the output voltage of the two RS-232 drivers. It is better to use software which doesn't care about DCD, but does hardwarehandshaking via CTS/RTS only. The circuitry is completed by connecting five capacitors to the IC as it follows. The MAX232 needs 1.0F capacitors, the MAX232A needs 0.1F capacitors. MAX232 clones show similar differences. It is recommended to consult the corresponding data sheet. At least 16V capacitor types should be used. The first pin is always where the plus pole of the capacitor should be connected to. 2.4 USB <-> RS-232 Converter With the rise of mobile phones so called data cables for these phones have also become popular. These are cables to connect the mobile phone to a serial interface of a computer. The interesting thing is that modern mobile phones work with 3.3V logic, and older phones with 5V logic on their data buses. So these data cables must and do convert the phone logic voltage levels to and from RS232 voltage levels. No-name data cables have become rather cheap (as opposite to original phone-brand data cables). The cheap cables with their voltage converters can be used as an alternative to home-made MAX232-based circuitry. The advantage is that the cables occupy much less space (the converter is usually inside the RS232 plug). Such a cable also saves the effort to solder a circuitry board. Another advantage, which can also be a disadvantage of such a data cable is that they usually take their power from the RS232 connector. This saves an external power supply, but can also cause problems, because the RS232 interface is not designed to power some logic and the DTE might not provide enough power. Another disadvantage is that many of these cables just support RX and TX (one receiver, one driver), and not two drivers/receivers as the MAX232. So there is no hardware handshake possible. Finally, when using such a cable it should be made sure that they convert to the desired voltage (3.3V or 5V). USB to Serial interface cables often have two components: a USB transceiver that outputs serial data; and a voltage shifter to produce standards-compliant RS-232 voltages. It is often possible to throw away (ignore, desolder, cut-out) the USB part of these cables, connect an external 5V power source (or abuse the RS-232 interface) to replace the power coming from the USB bus and to just use the RS-232 levelshifter. All this is probably as much work as using a MAX232A, although you get one RS-232 connector for free. On considering a USB cable, it is also worthwhile to consider using USB directly, instead of RS-232. Many USB transceiver chips can be integrated directly into circuits, eliminating the need for voltageshifting components. Parts such as the FTDI FT232BM even have an input allowing designers to select 5V or 3.3V output levels. Most of these USB transceiver chips are available as surface-mount components only. But some vendors offer DIP-sized preassembled modules, often at competitive prices, and often with free or cheap drivers or driver developmentenvironments.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

37

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 23: DB9 Male Connector

2.5 Serial Port


A serial port has 9 pins as shown. 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. 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, hence not required for our purpose. In fact, even pin 2 is also not required if we dont need to receive any data from our robot. At the receivers side (robot), a microcontroller with UART (Universal Asynchronous Receiver Transmitter) is required aboard the robot, to interpret the serial data. Most of the microcontrollers like AVR ATMEGA 16, Atmel/Philips 8051 or PIC microcontrollers have a UART. The UART needs to be initialized to receive the serial data from PC. The standard used for serial communication is RS-232 (Recommended Standard 232). The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels. Valid signals are plus or minus 3 to 15 volts. Now we know that this is not the voltage level at which our microcontroller works. Hence, we need a device which can convert this voltage level to that of CMOS, i.e., logic 1 = +5V and logic 0 = 0V. This task is carried out by an IC MAX 232, which is always used with four 10uF capacitors. The circuit is as shown:

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

38

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 24: RS232 Connections

*Note: The Tx and Rx shown in above figure (pins 11 and 12 of MAX232) are the Tx and Rx of microcontroller. For example, PD0 and PD1 in Atmega16. For controlling the robot via serial port, 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, some predefined codewords (lets say A=Left, B=Right, C=Forward, D=Backward, E=Pick object, etc.) are sent to microcontroller through the serial port. First you must check from the Device Manager of your system (My Computer->System Properties>Device Manager->Ports) that what the name is given to the serial port of your computer (or the virtual serial port of USB to Serial Converter). Lets say it is COM1.

Fig 25: Screenshot of Device Manager showing Serial Port detected at COM1

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

39

AIR GESTURE CONTROLLED ROVER (AGCRov)


Now we can access the serial port from MATLAB by defining a serial port object, lets say by the name ser as >>ser=serial ('COM1','BaudRate',9600); This defines the Baud rate as 9600 bps. You can use any Baud rate, but make sure that the same Baud rate has been configured in the onboard receiver microcontroller also. 9600 bps is the default baud rate. Now we open the serial port and send data through it. >>fopen(ser); >>fwrite(ser,'A'); % Move robot left >>fwrite(ser,'E'); % Pick object As the microcontroller interprets the serial data from the PC, it suitably controls the motors through its output pins, which are connected, to the motor driver or H-bridge (like L293 or L298). 2.6 Webcam A webcam is a video camera that feeds its image in real time to a computer or computer network. Unlike an IP camera (which uses a direct connection using ethernet or Wi-Fi), a webcam is generally connected by a USB cable, FireWire cable, or similar cable. The webcam have certain properties.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

40

AIR GESTURE CONTROLLED ROVER (AGCRov) 3. SOURCE CODE


3.1 FOR MATLAB
functionvarargout = Minortest1(varargin) % MINORTEST1 MATLAB code for Minortest1.fig % MINORTEST1, by itself, creates a new MINORTEST1 or raises the existing % singleton*. % % H = MINORTEST1 returns the handle to a new MINORTEST1 or the handle to % the existing singleton*. % % MINORTEST1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MINORTEST1.M with the given input arguments. % % MINORTEST1('Property','Value',...) creates a new MINORTEST1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Minortest1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Minortest1_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help Minortest1 % Last Modified by GUIDE v2.5 21-Oct-2013 11:25:31 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Minortest1_OpeningFcn, ... 'gui_OutputFcn', @Minortest1_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); ifnargin&&ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end ifnargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

% --- Executes just before Minortest1 is made visible. function Minortest1_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure

41

AIR GESTURE CONTROLLED ROVER (AGCRov)


% eventdata % handles % varargin reserved - to be defined in a future version of MATLAB structure with handles and user data (see GUIDATA) command line arguments to Minortest1 (see VARARGIN)

% Choose default command line output for Minortest1 handles.output = hObject; axes(handles.axes1); imshow('blank.jpg'); axes(handles.axes2); imshow('blank.jpg'); set(handles.edit1,'String',''); handles.t=0; handles.vid=videoinput('winvideo',1,'YUY2_1280x720'); set(handles.vid,'ReturnedcolorSpace','rgb'); set(handles.vid,'FramesPerTrigger',1); set(handles.vid,'TriggerRepeat',inf); triggerconfig(handles.vid,'manual'); % Update handles structure guidata(hObject, handles); % UIWAIT makes Minortest1 wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. functionvarargout = Minortest1_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;

% --- Executes on button press in Start. functionStart_Callback(hObject, eventdata, handles) % hObject handle to Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) start(handles.vid); for i=1:20 trigger(handles.vid); handles.im=getdata(handles.vid,1); axes(handles.axes1); imshow(handles.im); end guidata(hObject, handles); % --- Executes on button press in Trigger. functionTrigger_Callback(hObject, eventdata, handles) % hObject handle to Trigger (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [x y k]=impixel(handles.im);

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

42

AIR GESTURE CONTROLLED ROVER (AGCRov)


s=size(handles.im); thr=0.34; r_min=k(1)-thr*(k(1)); g_min=k(2)-thr*(k(2)); b_min=k(3)-thr*(k(3)); r_max=k(1)+thr*(k(1)); g_max=k(2)+thr*(k(2)); b_max=k(3)+thr*(k(3)); while (1) trigger(handles.vid); handles.im1=getdata(handles.vid,1); im_r=handles.im1(:,:,1); im_g=handles.im1(:,:,2); im_b=handles.im1(:,:,3); im_new=zeros(s(1),s(2)); for i=1:s(1) for j=1:s(2) if(im_r(i,j)>=r_min&&im_r(i,j)<=r_max&&im_g(i,j)>=g_min&&im_g(i,j)<=g_max&&im_b(i,j )>=b_min&&im_b(i,j)<=b_max) im_new(i,j)=1; else im_new(i,j)=0; end end end im_bw=bwareaopen(im_new,100); im_bwfill=imfill(im_bw,'holes'); axes(handles.axes2); imshow(handles.im1); holdon dd=bwconncomp(im_bwfill,8); val=regionprops(dd,'All'); l=0; for i=1:size(val,1) R=val(i,1).EquivDiameter/2; xc=val(i,1).Centroid(1); yc=val(i,1).Centroid(2); x=0:0.001:1; z=xc+R*cos(2*pi*x); z1=yc+R*sin(2*pi*x); holdon; text(xc,yc,num2str(i)); l=l+1; end set(handles.edit1,'String',l); p=get(handles.edit1,'String'); if(strcmp(p,'1')) f1=serial('COM12'); fopen(f1); fprintf(f1,'%c','F'); fclose(f1); delete(f1); clearf1; elseif (strcmp(p,'2')) b1=serial('COM12'); fopen(b1);

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

43

AIR GESTURE CONTROLLED ROVER (AGCRov)


fprintf(b1,'%c','B'); fclose(b1); delete(b1); clearb1; elseif (strcmp(p,'3')) l1=serial('COM12'); fopen(l1); fprintf(l1,'%c','L'); fclose(l1); delete(l1); clearl1; elseif (strcmp(p,'4')) r1=serial('COM12'); fopen(r1); fprintf(r1,'%c','R'); fclose(r1); delete(r1); clearr1; end end guidata(hObject, handles); % --- Executes on button press in Stop. functionStop_Callback(hObject, eventdata, handles) % hObject handle to Stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) stop(handles.vid); delete(handles.vid); clearhandles.vid; guidata(hObject, handles);

function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc&&isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

44

AIR GESTURE CONTROLLED ROVER (AGCRov)

Fig 26: Screenshot of GUI in working project

3.2 FOR IAR EMBEDDED WORKBENCH #include "msp430g2553.h" #define UART_TXD 0x02 #define UART_RXD 0x04 // Hardware-related definitions // TXD on P1.1 (Timer0_A.OUT0) // RXD on P1.2 (Timer0_A.CCI1A)

#define UART_TBIT_DIV_2 (1000000 / (9600 * 2)) // Conditions for 9600 Baud SW UART, SMCLK = 1MHz #define UART_TBIT (1000000 / 9600) // Globals for full-duplex UART communication unsignedinttxData; // UART internal variable for TX unsigned char rxBuffer; // Received UART character voidTimerA_UART_tx(unsigned char byte); voidTimerA_UART_print(char *string); void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = 0x00; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; P1OUT = 0x00; // Stop watchdog timer // Set DCOCLK to 1MHz // Function prototypes

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

// Initialize all GPIO

45

AIR GESTURE CONTROLLED ROVER (AGCRov)


P1SEL = UART_TXD + UART_RXD; P1DIR = 0xFF & ~UART_RXD; P2DIR |= 0xFF; P2OUT &= 0x00; // ConfiguresTimer_A for full-duplex UART operation TA0CCTL0 = OUT; // Set TXD Idle as Mark = '1' TA0CCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int TA0CTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode _BIS_SR(GIE); // Enable CPU interrupts // Send test message // Timer function for TXD/RXD pins // Set all pins but RXD to output

TimerA_UART_print("G2553 TimerA UART\r\n"); TimerA_UART_print("READY.\r\n");

while(1){ _BIS_SR(LPM0_bits); TimerA_UART_tx(rxBuffer);

// Wait for incoming character // Enter low poser mode // Transmit the received data

if (rxBuffer=='F' || rxBuffer=='f') P2OUT = 0x0A; else if (rxBuffer=='B' || rxBuffer=='b') P2OUT = 0x06; else if (rxBuffer=='L' || rxBuffer=='l') P2OUT = 0x01; else if (rxBuffer=='R' || rxBuffer=='r') P2OUT = 0x08; else P2OUT = 0x00; } } voidTimerA_UART_tx(unsigned char byte) { while (TACCTL0 & CCIE); TA0CCR0 = TAR; TA0CCR0 += UART_TBIT; TA0CCTL0 = OUTMOD0 + CCIE; // Outputs one byte using the Timer_A UART // Ensure last char got TX'd // Current state of TA counter // One bit time till first bit // Set TXD on EQU0, Int
Page Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

46

AIR GESTURE CONTROLLED ROVER (AGCRov)


txData = byte; txData |= 0x100; txData<<= 1; } // Load global variable // Add mark stop bit to TXData // Add space start bit

voidTimerA_UART_print(char *string) { while (*string) TimerA_UART_tx(*string++); } #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A0_ISR(void) { static unsigned char txBitCnt = 10; TA0CCR0 += UART_TBIT; if (txBitCnt == 0) { TA0CCTL0 &= ~CCIE; txBitCnt = 10; } else { if (txData& 0x01) TA0CCTL0 &= ~OUTMOD2; else TA0CCTL0 |= OUTMOD2; } txData>>= 1; txBitCnt--; }

// Prints a string using the Timer_A UART

// Timer_A UART - Transmit Interrupt Handler

// Add Offset to CCRx // All bits TXed? // All bits TXed, disable interrupt // Re-load bit counter

// TX Mark '1' // TX Space '0' // Shift right 1 bit

#pragma vector = TIMER0_A1_VECTOR __interrupt void Timer_A1_ISR(void) { static unsigned char rxBitCnt = 8;

// Timer_A UART - Receive Interrupt Handler

switch (__even_in_range(TA0IV, TA0IV_TAIFG)) {

// Use calculated branching

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

47

static unsigned char rxData = 0;

AIR GESTURE CONTROLLED ROVER (AGCRov)

case TA0IV_TACCR1: TA0CCR1 += UART_TBIT; if (TA0CCTL1 & CAP) { TA0CCTL1 &= ~CAP; TA0CCR1 += UART_TBIT_DIV_2; } else { rxData>>= 1; if (TA0CCTL1 & SCCI) rxData |= 0x80; rxBitCnt--; if (rxBitCnt == 0) { rxBuffer = rxData; rxBitCnt = 8; TA0CCTL1 |= CAP; _BIC_SR(LPM0_EXIT); } } break; }}

// TACCR1 CCIFG - UART RX // Add Offset to CCRx // Capture mode = start bit edge // Switch capture to compare mode // Point CCRx to middle of D0

// Get bit waiting in receive latch

// All bits RXed? // Store in global variable // Re-load bit counter // Switch compare to capture mode // wake up from low power mode.

Fig 27: Air Gesture Controlled Rover


Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

48

AIR GESTURE CONTROLLED ROVER (AGCRov)

4.CONCLUSION
The integration of Embedded system with Image Processing using MATLAB has been performed. AGCRov uses two modules Hardware on MSP430 and Software on MATLAB which is integrated via UART. The Rover accepts the control signals issued by the user. The user uses number of fingers to move the rover in particular direction. These control signals are accepted over serial communication by the MSP430 MCU which then directs the DC motors to move in the appropriate direction. The motors are driven by L293D IC for maximum efficiency.

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

49

AIR GESTURE CONTROLLED ROVER (AGCRov)

5.REFERENCES
1. www.e2e.ti.com 2. www.mathworks.com 3. www.msp430.com 4. www.embeddedrelated .com 5. http://www.instructables.com/id/MATLAB-to-PIC-serial-interface/ 6. http://www.magna-power.com/applications/interfacing-matlab-through-rs232 7. http://mbed.org/cookbook/Interfacing-with-Matlab

Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan

Page

50

Anda mungkin juga menyukai