CONTROL MOBILE ROBOT BY HAND MOVEMENT VIA BLUETOOTH

23/6/2013 23/6/2013 23 / 6 / 2013 CONTROL MOBILE ROBOT BY HAND MOVEMENT VIA BLUETOOTH KESAVA RAO A/L GIAMASROW A thesis awarded in fulfilment o...
Author: Harold Gregory
11 downloads 0 Views 1MB Size
23/6/2013

23/6/2013

23 / 6 / 2013

CONTROL MOBILE ROBOT BY HAND MOVEMENT VIA BLUETOOTH

KESAVA RAO A/L GIAMASROW

A thesis awarded in fulfilment of the requirement for the award of Bachelor of Engineering (Electrical – Mechatronics)

Faculty of Electrical Engineering Universiti Teknologi Malaysia

June 2013

ii

iii

Dedicated to my beloved family members and friends for their support, belief, help, and motivation.

iv

ACKNOWLEDGEMENT

First and foremost I would like to express my gratitude to my supervisor, Dr. Mohamad Hafis Izran Bin Ishak for the guidance, advice, and motivation in completing this project.

Next, my appreciation also goes to my family who had supporting me all the way spiritually and financially which are my greatest motivation in this project. Finally, I would like express my appreciation to the supports and helps that offered indirectly and directly by my friends.

v

ABSTRACT

Controller is a device that used to control the movement of the robot. The controller will send instructions (data) to the robot and the robot will move according to the instruction (data) that received. The controllers that available usually wired and using button system to control the robot. A wired controller will be connected to the robot with a wire. The wire will be the medium between the controller and the robot, so instruction (data) can be sent from the controller to the robot. This type of controller has a disadvantage. Needs long wire if want to control the robot from long distance. In this project, Bluetooth will be used as medium between the controller and the robot. The movement of the robot will be controlled by the movements of the hand. BlueBee (Bluetooth module) will be used to receive the data from controller. PIC microcontroller will be used as a microcontroller in the robot. This microcontroller will receive the data from the BlueBee and execute the program according to the data. In the end of this project, the movement of the robot can be controlled according to the movement of the hand and wirelessly.

vi

ABSTRAK

Pergerakan robot boleh dikawal dengan mengunakan sebuah alat elektronik yang dipanggil sebagai pengawal. Alat mengawal ini akan menghantar isyarat kepada robot dan robot tersebut akan bergerak mengikut isyarat yang dihantar. Alat pengawal yang ada biasanya berwayar dan mempunyai sistem butang. Wayar akan disambungkan kepada robot dan isyarat yanag hendak dihantar akan melalui wayar tersebut. Tetapi cara ini menpunyai keburukannya iaitu panjang wayar tersebut. Wayar yang panjang diperlukan jika hendak kawal robot pada jarak yang jauh dan harganya mahal. Dalam projek ini Bluetooth akan digunakan sebagai medium untuk menhantar isyarat dari alat pengwal ke robot. Manakala, pergerakan tangan akan digunakan untuk mengawal pergerakan robot. BlueBee ( modul Bluetooth ) dan chip PIC akan digunakan di dalam project ini. Pada akhir project ini, pergerakan robot boleh dikawal dengan pergerakan tangan dan isyarat akan dihantar melalui Bluetooth.

vii

TABLE OF CONTENTS

CHAPTER

CHAPTER 1

CHAPTER 2

TITLE

PAGE

DECLARATION

ii

DEDICATION

iii

ACKNOWLEDGEMENT

iv

ABSTRACT

v

ABSTRAK

vi

TABLE OF CONTENTS

vii

LIST OF TABLES

xi

LIST OF FIGURES

xii

LIST OF ABBREVIATIONS

xiv

INTRODUCTION 1.1

Background of The Study

1

1.2

Problem Statement

1

1.3

Objective

2

1.4

Scope

3

1.5

Outline of The Thesis

3

1.6

Summary of The Work

4

LITERATURE REVIEW 2.1 Related Project

5

2.1.1 Bluetooth Enable Mobile Robot

5

2.1.2 Using Bluetooth Wireless Technology

6

ix

in Vehicle 2.1.3 Development Of A Bluetooth Network

7

Based LCD Messaging System 2.2 Bluetooth 2.2.1 Bluetooth Characteristic

8 8

2.3 Bluetooth Development

9

2.4 Bluetooth Core System

9

2.5 Peripheral Interface Controller /

12

Programmable Intelligent Computer (PIC) 2.6 Microsoft Visual Basic 2010

15

2.7 HyperTerminal

16

2.8 Universal Asynchronous Receiver-Transmitter (UART) 2.9 Summary

CHAPTER 3

18 20

RESEARCH METHODOLOGY 3.1

Introduction

21

3.2 Project Development

21

3.3 Gantt Chart

24

3.4 Hardware Implementation

26

3.4.1 PIC 18F4520

26

3.4.2 Cytron Bluetooth Module (BlueBee)

27

3.4.3 UC00B

29

3.4.4 Hand Controller

30

3.5 Software Implementation

31

3.5.1 MPLAB IDE

32

3.5.2 Visual Basic 2010

33

3.5.3 Multisim

34

3.6 Baud Rate Calculation

36

3.7 Summary

36

x

CHAPTER 4

CHAPTER 5

RESULTS AND DISCUSSIONS 4.1 Result

37

4.2 Discussion

41

CONCLUSIONS AND RECOMMENDATIONS 5.1

Conclusions

43

5.2

Recommendations

43

REFERENCES

45

APPENDIXS

46

xi

LIST OF TABLES

TABLE NO.

TITLE

PAGE

2.4

Operating Frequency Bands

10

3.3.1

Gantt chart for FYP 1

24

3.3.2

Gantt chart for FYP 2

25

3.4.2

Pin Functions

28

xii

LIST OF FIGURES

FIGURE NO.

TITLE

PAGE

1.1

Project Flow

4

2.1

Architecture of The Project

6

2.2

The Bluetooth Configuration in the Vehicle

7

2.3

Project Idea

8

2.4

Bluetooth Core

10

2.5

The Bluetooth Protocol Stack

11

2.6

Basic PIC Block Diagram

13

2.7

PIC Development Process

15

2.8

HyperTerminal

17

2.9

Baud Rate Selection

17

2.10

COM Port Specifications

18

2.11

Asynchronous Code Format / Frame Transmits

19

2.12

Transmit PIC UART Circuit

19

2.13

Receive PIC UART Circuit

20

3.1

Project Architecture

22

3.2

Flow Chart of the Project Development

23

3.3

Pin Diagram for PIC18F4520

27

3.4

BlueBee

28

3.5

Bluebee Layout

28

3.6

Connect Microcontroller to PC

30

3.7

UC00B

30

3.8

Hand Controller Concept

31

3.9

MAPLAB v8.84

32

xiii

3.10

Output Report Done by MPLAB IDE

32

3.11

PICkid2 v2.61

33

3.12

Serial COM Port GUI

34

3.13

Circuit for the Mobile Robot

35

3.14

Hand Controller Circuit

35

4.1

Top View of Real Mobile Robot

37

4.2

Side View of the Real Mobile Robot

38

4.3

Bluebee Module Circuit

38

4.4

Hand Controller

39

4.5

Serial Communication GUI

39

4.6

Alternative Method to Control Mobile Robot

40

4.7

Result shown in HyperTerminal after ‘w’ is Pressed

40

4.8

After ‘x’ is pressed

41

xiv

LIST OF ABBREVIATIONS

RF

-

Radio Frequency

PC

-

Personal Computer

LCD

-

Liquid-Crystal Display

PIC

-

Programmable Intelligent Computer

UART

-

Universal Asynchronous Receiver-Transmitter

ISM

-

industrial Scientific Medicine

USB

-

Universal Serial Bus

PCM

-

Pulse-code modulation

SIG

-

Special Interest Group

TCP

-

Transmission Control Protocol

LPM

-

Link Protocol Manager

SDP

-

Session Description Protocol

L2CAP

-

Logical Link Control and Adaptation Protocol

PPP

-

Point to point Protocol

ALU

-

Arithmetic Logic Unit

CPU

-

Central Processing Unit

RC

-

Resistor Capacitor

EPROM

-

Erasable Programmable Read Only Memory

UV

-

Ultra violet

VB

-

Visual Basic

IDE

-

Integrated Development Environment

GUI

-

Graphical User Interface

OS

-

Operating System

RSR

-

Receive Shift Register

TSR

-

Transmit Shift Register

xv

PIR1

-

Peripheral Interrupt Request Register 1

LAT

-

Latch

GND

-

Ground

FIFO

-

First Come First Out

TXD

-

The Transmit Data

RXD

-

The Read Data

IP

-

Internet Protocol

DNS

-

Domain Name Service

BOOTP

-

Bootstrap Protocol

xvi

LIST OF APPENDICES

APPENDIX

TITLE

PAGE

APPENDIX A

Mobile Robot Coding

46

APPENDIX B

Hand Controller Coding

51

APPENDIX C

Program of Serial Communication Graphical User

54

Interface (GUI)

CHAPTER 1

INTRODUCTION

1.1

Background of The Study

Mobile robot can be classified as a moving robot that can move from one point to other point and not fixed on one particular point. The movement of the mobile robot can be controlled by wired, wireless or “self-thinking”. Wireless mobile robot is very popular nowadays. Control and communicate with mobile robot without using wired connection is called wireless controlling. Bluetooth, radio frequency (RF) and infrared are commonly used in wireless controller. The rapid development of wireless technology particularly in Bluetooth technology makes latest gadgets and home appliance comes with Bluetooth compatibility so it can be controlled wireless. To control mobile robot wired and wireless need some controller to guide the motion and the direction of the robot. There is several types of controllers that are most commonly used, such as joy stick, kinect and motion sensor controller. Using human parts body and human motion to control mobile robot is technology that is rapidly developing.

2

1.2

Problem Statement

Currently there are lot of controller that already exist to control the mobile robot whether wired or wirelessly. There are controller that can be controlled the movement of the mobile robot, but using wired method to communicate and to send data to the mobile robot. A wire from controller will be connected to mobile robot. This method has disadvantages. The first disadvantage is the connection between the robot and the controller can be disconnected if the wire is accidently cut off. The second disadvantage is the range to control the mobile robot is restriction due to the length of the wire. Longer wire will cost lot of money. Wireless controllers are also available. Most of controllers are sending the date via radio frequency (RF) or inferred technology. Using RF will required a long antenna on the controller to transmit the date to the mobile robot and causes to build much bigger controller. RF signal also can be interrupted and overlapped by other device that has same frequency. It cause the mobile robot can be controlled by other unwanted person. The efficiency and accuracy of inferred controller can be effect by strong sun light or regular light. To control lot of movement and combination movement needs lot of key buttons and button combinations. Few buttons on the controller only can controller few directions and movements.

1.3

Objective

In this project have three main objectives. The first objective of this project is to controller the mobile robot wirelessly. There is no any wired connection between the mobile robot and the controller. The second objective of this project is to establish the Bluetooth connection between the controller and the mobile robot, so

3

the communication of data transmitting and data receiving between the controller and the mobile robot occur wireless. The third objective of this project is using hand gesture (hand movement) as the controller to the directions and the movement of the robot.

1.4

Scope

The scope of this project can be divided to three main scopes. The first scope of this project is to build both hand controller and the mobile robot. This is including the electrical and mechanical parts. The second scope is use only right hand as the controller to control the mobile robot. The third scope of this project is only using five movement of the mobile robot can be controlled , that are moving right, left, back, in front and stop.

1.5

Outline of The Thesis

This thesis consists of six chapters. In the first chapter, we will discuss about background of the study, our project objectives, scopes and any other relevant information as introduction. While in Chapter 2, more theory and literature reviews that have been done before will be discussed. It will discuss about the advantages of using Bluetooth compare to radio frequency and infrared. It also discuss about the previous project done by other person by using Bluetooth. In chapter 3, we will discuss on the methodology of this project. Result will be presented in chapter 4. Lastly, chapter 5 discusses the conclusion and future recommendation work that can be done in order to improve this project.

4

1.6

Summary of The Work

Review and studying about the project

Design and build mechanism part

Assembly both mechanical and electronics part

Do programming for hand controller and mobile robot Test the functionality of the project

Troubleshoot the problems

Project done

Figure1.1

Project Flow

CHAPTER 2

LITERATURE REVIEW

2.1

Related Project

2.1.1

Bluetooth Enable Mobile Robot(Yeong Che et al., 2002)

This project was conducted by Yeong Che Fai, Shamsudin H.M.Amin , Norsheila bt Fisal and J.Abu Bakar. The purpose of this project is to fetching the algorithm from the server using Bluetooth. It is caused by the limitation of memory space in the microcontroller. In this project Handy Board MC68HC11 is used to send data from a PC and also to receive data from the sensors. The sensors are connected on the Handy Board by Bluetooth.

6

Figure 2.1

Architecture of the project

2.1.2 Using Bluetooth Wireless Technology in Vehicles

Plenty usage of wire in the vehicles makes the vehicles in disadvantage condition. It makes the vehicles heavy, complex and very expensive. Furthermore the when the function in the vehicle is increased, the usage of the wired also increased.(Ye and Li, 2005) The objective of this project is to reduce the usage of the wire by replacing with Bluetooth and increase few features in the car by using Bluetooth technology.

7

Figure 2.2

The Bluetooth Configuration in the Vehicle

Bluetooth module is used to communicate and control with the devices in the car. It can be connect 6 devices in one time. It cause the usage of the wire in the vehicle is reduced.

2.1.3

Development of A Bluetooth Network Based LCD Messaging System

This project developed by(Hon, 2009) Siow Li Hon an electrical engineering student from UTM student on 2009. The main propose of this project is to send message from a personal computer or laptop to the LCD by using Bluetooth.

8

Figure 2.3

2.2

Project Idea

Bluetooth

Bluetooth is a latest wireless technology that transmits and receives data in short range. The name of Bluetooth is taken from one of Denmark king “Harald Bluetooth”. Bluetooth is a wireless technology that provide low cost, low power , small in size electrical device and high capacity in voice and data communication in the 2.4 GHz ISM(industrial Scientific Medicine) unlicensed band and it can be used globally. It can say that Bluetooth is royalty-free wireless technology.(Yabin Liu, 2006)

2.2.1

Bluetooth Characteristic

There are several basic attribution that makes Bluetooth wireless technology is so unique. There are:-(Zhang Pei, 2000)

9



The basic and nominal range of Bluetooth transition and reception is from 10 meter to 100 meter at +20dBm.



Maximum bandwidth that can be produces is 1 Ms/s symbol rate



Can prevent any interruption with rapid frequency hopping (1660 hops/s) and a Time – division Dupex scheme is used



Capability with USB , UART and PCM



Maximum data transfer rate is 723.2 kb/s with one connection/ 3 voice channel



Can increase the short data packets to its maximum level even interruption occurs



2.3

Can make connection up to 7 devices in the same period

Bluetooth Development

In February 1998, only small amount of company that interested in the development of the Bluetooth technology was form a new group. Special Interest Group (SIG) was form with initial group members only consist of five companies, there are Ericsson, IBM, Intel, Nokia and Toshiba. Currently there are more than thousand company enrol in that group. From that group, they come out with Bluetooth specification, so it can develop the Bluetooth technology. The main purpose of the Bluetooth specification is to develop ideas to make connection each Bluetooth device.(Ye Chen 2005)

10

2.4

Bluetooth Core System

Bluetooth device is build with three parts, there is radio frequency (RF) transmitter, Base- band and protocol stack / link manager. Bluetooth RF emits 2.4 GHz frequency wave. In the RF system employs a frequency hop transceiver to prevent interference and fading of the signal. RF uses a shaped binary frequency modulation to reduce transceiver complexity. The RF channel according to certain country: (Ye Chen 2005) Table 2.4

Operating Frequency Bands

Countries

ISM range MHz

RF Channels

USA, Europe and other

2400-2483.5

2402 +kMHz

countries

k=0,….., 78

Spain

2445-2475

2449+kMHz k=0,…,22

France

2446.5-2483.5

2454+kMHz k= 0,….,22

RF

Figure 2.4

Baseband

Link manager

Host

Bluetooth Core(Bhagwat, 2001)

Base band and Link Control plays main role for RF to enable the link of physical RF to form Piconet.(M. Kalia, 2000). This two main thing makes the Bluetooth to produce synchronization and transmission frequency hopping sequence.

11

Application

ATCom

UDP/TCP/IP

OBEX

Software

PPP TCS

Audio

RFComm

SDP

L2CAP

Host Control Interface (HCI) Link Manager

Hardware

BaseBand

Figure 2.5

The Bluetooth Protocol Stack (Yabin Liu, 2006)

Main function of Link Protocol Manager (LPM) is to setup a link between Bluetooth units. It will control and negotiation of packet seizes when the data is transmitting.LMP also functions to control power consumption and encryption key for authentication and encryption. The HCI gives a interface measure to connect between Bluetooth hardware capability and software with USB, UART and PCM. HCI consist of LPM, bandbase and registers. L2CAP (Logical Link Control and Adaptation Protocol) act like connection-oriented and connectionless data service to higher layers. The other task that L2CAP can do is multiplexing, reassembling and segmentation. Meanwhile RFCOMM protocol is a serial port emulation protocol. This protocol will emulate RS232 control and data transmitting/receiving over the baseband. TCS Binary ( Telephony Control- Binary ) is gives ability to exchange the information signalling and stated of the call control of signalling to build and release data calls between Bluetooth. SD 2 v2.61 P or Service Discovery Protocol will

12

function to detect the other Bluetooth services that available or not available around the area. Audio in the Bluetooth will send audio signal to other Bluetooth unit that available. PPP (Point to point Protocol) is a packet-oriented protocol that used to convert packet of data signal and also act point to point connections. AT commands is provides transmitting control signal for TCS. UDP/TCP/IP provides ability to Bluetooth units to communicate with other Bluetooth units when connected.

2.6

Peripheral Interface Controller / Programmable Intelligent Computer (PIC)

PIC is one of the powerful microcontrollers. PIC composes of processor, RAM, ROM, oscillator, watchdog, timer, interrupts and I/O ports within one single chip. Basically, it is only consume small space compare to microprocessor that have to use external components such as RAM, oscillator and other components that consume lot of space. Inside of PIC’s central processing unit (CPU) contain a unit that control all the arithmetic and logic process, which is called as Arithmetic Logic Unit (ALU). ALU is very important unit because it will control and process the mathematical calculations and logic operations. The main differences between the PIC and the other microcontroller are, PIC only has one main register for logic and arithmetic operations and Working (W) register inside CPU will keep any data that will transfer inside the CPU. Furthermore, data register inside CPU can be divided into two main sections the first sections acting as I/O and Control and the second section serving wholly as RAM. Besides that, inside of PIC have different type of busses that separated (Harvard architecture). The busses used to speed up data transfer, data throughput, improve software safety and allow instantaneous access to both program memory and data.

13

PROG EEPROM

PC

STATUS

STACK

RTCC

WATCH DOG TIMER

ALU

GENERAL REGISTER FILE PORT A

OSC

PORT B

A/D EEPROM PORTC

CONFIG FUSES

F

Figure 2.6

Basic PIC Block Diagram

PIC has 4 types of ‘cores’ that has different amount of instruction types. The first one is 14 bits core with 35 instructions (PIC model: 16Cxxx, 16Fxxx). Second type of core is a 12 bits core with 33 instructions (12C50x, 16C5x). Third type is a 16 bits core with 58 instructions (18Cxxx, 18Fxxx) and the final type of the core is a “Enhanced” 16 bits core with 77 instructions (18Cxxx, 18Fxxx). Besides that, PIC also comes up with different number of digital input/output pins (DIP), they are 8 pins of DIP (12C50Cx and 12c67x), 18 pins of DIP (16Cxxx, 16Fxxx), 28 pins of DIP ( 16C5x,16Cxxx) and 40 pins of DIP ( 16Cxxx and 17C4x) and 44-68 pins of DIP (16Cxxx and 17Cxxx). (Johnson, 2004) Clock is important part for the PIC. It is because clock enabled the PIC microcontroller and makes the microcontroller to functions or works. To generate the clock pulse, crystals, clock oscillators or RC circuit (Timer 555) can be used. Most of PIC microcontrollers already have a build in RC clock. Usually the value of build in RC clock is 4MHz. But using the internal clock has a disadvantage compare to using external clock. The disadvantage is the internal RC circuit is not so accurate. The advantages of using internal clock is not requires any external components and the clock cycle can be increased until 40MHz. For example, for PIC model 12C50x the maximum clock cycle is 4MHz,for PIC model 12C67x is 10MHz,for PIC models

14

16Cxxx and 16Fxxx are 20MHz, for PIC models 17C4x and 17C7xxx are 33MHz and finally for PIC models 18Cxxx and 18Fxxx are 40MHz. Program space is different for each PIC model chip. For example PIC model 12C508 has 512 12 bits instruction code spaces, PIC model 16F84A has 1024 14 bits instruction code spaces and 16F877 has 8192 14 bits instruction code spaces. PIC microcontroller has two types of program instructions storages, they are FLASH and EPROM. EPROM (Erasable Programmable Read Only Memory) requires high voltage to program the microcontroller. Usually at least 13 V is needed to program the microcontroller. To erase the program, UV (Ultra violet) ray is used. Meanwhile FLASH has capability of rewritable. It can rewrite the previous instruction inside the microcontroller without using any erase method. This process can be done even within the microcontroller. So the process of the writing and erasing the instruction inside the microcontroller can be done very fast and can be done more than 100 thousand times. PIC model that using EPROM has ‘C’ indicate in its model name, for example 12C50x and 17C7xx. Meanwhile ‘F’ indicator is used in PIC model for FLASH like 16F84, 16F87x and more. Assemble language (low level language) and C language (high level language) are used to write source code.

15

Figure 2.7

2.6

PIC Development Process

Microsoft Visual Basic 2010

Microsoft Visual Basic 2010 is a software that used to design the application based on windows platform. C or C# is used as main language to designing the applications. Visual Basic (VB) can be categorised as a integrated development environment (IDE) and a third-generation event-driven programming language that developed by Microsoft for computer programming model. With VB , programmer

16

can develop GUI( Graphical User Interface) applications and other complex applications. (Peyrard, 2008) GUI is an application that helps user to communicate with computers and interact with electronics device using image rather than text command. Combination of visual arranging components that have specific attributes (serial communication, timer, etc) and C language coding is the method to program the VB. The advantage of VB is, user no needs to write very long coding line to create an application. It is because the components’ coding already defined in the Microsoft Visual Studio. (Potts and Sukittanon, 2012)

2.7

HyperTerminal

HyperTerminal is an application that used to make connection between two computers, or connection between a computer and an electronic device such as Bluetooth build in electronic devices. Modem, a null modem cable (used to emulate modem communication), or an Ethernet connections are the types of communication can made by HyperTerminal. For latest windows operating system (OS), windows Vista, Windows 7 and Windows 8, the HyperTerminal application didn’t include with the system. The application should be installed separately with third party software. (Sun-Mi and Nam-Hoon, 2004)

17

Figure 2.8

HyperTerminal

User can receive and view texts on the screen and furthermore, user also sent texts to the remote device. Baud Rate is the speed rate of data transmission in a specific system. Baud Rate shows an electrical oscillation per second that occurs during data transmission. The bigger the value of baud rate, the more bits per second are transferred. In HyperTerminal, baud rate can be selected according to remote device system. To make the connection between the computer and the other remote device, user should connect with specific COM port where the remote device is connected to the user computer.

Figure 2.9

Baud Rate Selection

18

Figure 2.10

2.8

COM Port Specifications

Universal Asynchronous Receiver-Transmitter (UART)

UART is a electronic device that convert data (bytes) from parallel to series form for outbound transmission. Shift register plays main role in translation between parallel form and serial form. Serial transmission of bits trough a single wire is cheaper compare to parallel transmission with multiple wires. Frame transmits of a single character is basically content a start bit ( bit number 1 and always logic ‘0’ ) , data bits ( bit number 2-9) and stop bits ( bit number 10-11 and always logic ‘1’).Time for the bit derived from start bit is 1 bit time, 1 bit time for each data bits and for stop bits may be 1 , 1.5 or2 bit times in duration. For microcontroller PIC’s UART, requires all bits that transmitted must be have duration of one bit times. So for PIC the duration of bits derived is always 10 bits times (1 start, 8 data, and 1 stop).

19

Bit Number

1

2

3

4

Start bit Start

Figure 2.11

5

6

7

8

9

Data bits

10

11

Stop bits

Data

Data

Data

Data

Data

Data

Data

Data

1

2

3

4

5

6

7

8

Stop

Asynchronous Code Format / Frame Transmits

Microcontroller PIC has full duplex UART. Duplex UART can transmit and receive data at the same time. Microcontroller PIC has two type of buffer, first transmit shift register (TSR) and receive shift register (RSR). To transmit data using UART from PIC, data write to the TXREG a special register. TXREG is an interrupt function under peripheral interrupt request register 1 (PIR1) register. When TXREG received a data, an interrupt process will start and the data inside TXREG automatically copied into TSR. The new data can be written again inside TXREG even data inside TSR is still sending. The data transmits on pin RC6/TX in PIC. Meanwhile, when a data is received, the data stored at RCREG and copied to RSR. RCREG is an interrupt function. When RCREG received data or the logic is ’1’, an interrupt function is carried out. Data received on pin RC7/RX.

Data Bus

Write To TXREG

TXREG

Automatic transfer when TSR is empty Stop bit=1

Start bit = 0

TSR( transmit shift register) Figure 2.12

RC6

Data Transmitted least significant bit first

Transmit PIC UART Circuit

20

RC7 RSR( receive shift register) Stop bit=1

Start bit=0

Automatically transfer when RSR empty

Two byte FIFO

RCREG Data Bus

Figure 2.13

2.9

Receive PIC UART Circuit

Summary

In this chapter, related projects that using Bluetooth is discussed. There are three related projects are discussed, Bluetooth enable mobile robot , Using Bluetooth wireless technology in vehicles and Development of a Bluetooth network based LCD messaging system. Furthermore, characteristic of the Bluetooth, Peripheral Interface Controller / Programmable Intelligent Computer and the working principle of Universal Asynchronous Receiver-Transmitter (UART) are discussed.

CHAPTER 3

METHODOLOGY

3.1

INTRODUCTION

The contents covered in this chapter discuss the technique, approach, and the method used to fulfil the projects objectives and also discusses the flow of the project. A systematic and well planned approach is necessary in order to complete this project.

3.2

Project Development

The development of this project can be divided to three parts. The first part is design and creates hand controller and mobile robot with onboard embedded system. The second part is creating a GUI in PC. And the final part is do programming for embedded system. The main function of GUI is to transfer data from two different ports and give an interface for user to control the robot. The information from PC will transferred to the mobile robot via Bluetooth. The mobile robot will be build with a Bluetooth module (BlueBee). The information from hand control will be

22

transferred to the mobile robot by using Bluetooth and PC (GUI and Bluetooth) will be medium so the transferring will occur.

PIC

BlueBee Module

UART

Bluetooth

GUI

Laptop Mobile Robot

UC00B (UART)

Hand Controller PIC

Figure 3.1

Project Architecture

23

SWITCH ON

Establish the Bluetooth connection

Do the hand gesture

Sent data to microcontroller via PC

Mobile robot movement

Stop

Figure 3.2

Move in front

Move left

Move right

Flow Chart of the Project Development

Move Behind

24

3.3

Gantt chart

Table 3.3.1

Gantt chart for FYP 1

Weeks Task

1

Project Title Selection FYP Proposal Research and analysis on the topic Meeting with Supervisor Project Planning and designing Slides Preparation FYP 1 Seminar Presentation Report Writing

2

3

4

5

6

7

8

9 10 11 12 13 14 15

25

Table 3.3.2

Gantt chart for FYP 2

Weeks Task Build hand controller and mobile robot Programming for hand controller and mobile robot Testing and troubleshooting Meeting with supervisor Preparing for presentation Report writing

Publication FYP 2 Seminar Presentation

1

2

3

4

5

6

7

8

9 10 11 12 13 14 15

26

3.4

Hardware implementation

In order to build this project two PIC 18F4520 microcontroller and a Bluetooth module is needed. Mobile robot is build with a PIC 18F4520 and a Bluetooth module. And another microcontroller is used in hand controller. UC00B will be used on hand controller as a UART device to connect with PC.

3.4.1

PIC 18F4520

PIC18F4520 is a 40 pin microcontroller. The operation voltage range for this chip is 2.0V to 5.5V. It has 32Kbytes 14-bit words FLASH program memory and 40MHz as the maximum operating frequency (Tclk). Beside that, it has 4 timers and 1 PWM module. Besides that, it has 1536 bytes data memory (‘file registers’) and 256 bytes EEPROM (non-volatile) data register. Its I/O port is divided into five ports; they are PORTA, PORTB, PORTC, PORTD and PORTE. Each port has three registers for its functionality. The registers are TRIS register (data direction register), LAT register (output latch) and PORT register (reads the levels on the pins of the device) . PORTA are a 6-bit wide and bi-directional port and PORTE is a 3-bit wide and bi-directional. Meanwhile the other ports are 8-bit wire and bi-directional. In order to make the ports as input or output, it is depends on TRIS. To set a PORTx pin as input pin, should set the corresponding TRISx bit (=1); meanwhile to set a PORTx pin as a output pin , TRISx bit (=0). The Data Latch register (LATx) also called as read - modifies – write operations. It will make the ports to read and write the latched output value for the port. PORTC.7 and PORTC.6 are representing the Addressable USART Asynchronous Receiving and Addressable USART Asynchronous Transmitting respectively. It can be used in serial communications.

27

Figure 3.3

Pin Diagram for PIC18F4520

3.4.2 Cytron Bluetooth Module (BlueBee)

BlueBee is Bluetooth module created by Cytron Technologies that located in Malaysia .The pinout of BlueBee is compatible and suitable for all kinds of microcontroller. BlueBee only support on the system that have 3.3 V power out. Larger voltage then 3.3 V will cost the module not function. BlueBee have two modes which is Transparent mode and AT mode. The baudrate of module may be set using AT commands/mode. The BlueBee module comes with an on-board antenna. It makes the module provides better signal quality The BlueBee is only a slave module. Communication between the two BlueBee modules is not possible.

28

Figure 3.4

Figure 3.5

Table 3.4.2

BlueBee

Bluebee Layout

Pin functions

Pin

Name

Description

1

3V3

3.3V (+) supply for BlueBee module

2

TXD

UART Data output

3

RXD

UART Data input

4

NA

NA

29

5

RESET

Reset for BlueBee module

6

P9

Connection Indicator, High = Connected, Low = No connection

7

NA

NA

8

P8

LED, Mode indicator, connected to BlueBee status LED

9

NA

NA

10

GND

11

NA

NA

12

CTS

UART clear to send, active low

13

NA

NA

14

NA

NA

15

NA

NA

16

RTS

UART request to send, active low

17

NA

NA

18

NA

NA

19

NA

NA

20

NA

NA

Ground port

NA: No connection needed

3.4.3 UC00B

UC00B is a USB to UART (Universal Asynchronous Receiver/Transmitter) converter device. This device should be connected with the Bluetooth module. This device is used to enabling Bluetooth wireless control. This device works in 3.3 V or 5 V, higher voltage then this will make the device malfunctions. Tx pin on BlueBee is connected with Rx on the UC00B and Rx pin on BlueBee is connected with Tx pin on UC00B.

30

Figure 3.6

Connect Microcontroller to PC

UC00B also will be used as a medium to connect hand controller circuit to the PC.

VCC RX TX GND

Figure 3.7

3.4.4

UC00B

Hand Controller

Hand controller is used as remote controller to control the mobile robot.

31

Figure 3.8

Hand Controller Concept

When the doing some hand gesture, the red colour metal will touch or not touch the brown colour metal. When the red colour metal touched the brown colour metal, the current will flow to ground and it will make the microcontroller detect the changes and identify the combination of input. The microcontroller will detect the input, and a program will execute the specified program. The data will be send from the microcontroller to the computer, to be transmit to the mobile robot via Bluetooth.

3.5

Software Implementation

MPLAB IDE, Multisim, and Visual Basic 2010 used to complete this project.

32

3.5.1

MPLAB IDE

MPLAB IBE v8,84 and PICkid2 v2.61 are used to generate the hex file and compile the program inside the PIC18F4520 microcontroller. If the program has any error the MPLAB will detect and point the location of the error. So the amendment can make on the program. Meanwhile PICkid 2 is also indicates memory space been used. PICkid 2 is used to program the microcontroller.

Figure 3.9

Figure 3.10

MAPLAB v8.84

Output Report Done by MPLAB IDE

33

Figure 3.11

3.5.2

PICkid2 v2.61

Visual Basic 2010

Visual Basic 2010 is used to build Graphic User Interface (GUI). The GUI will display the available COM port and will send the data from COM port to Bluetooth port in the computer. This GUI will show the data from hand controller transferred to mobile robot via Bluetooth port. Mobile robot is connected to COM port 10 and the hand controller is connected to COM port 13 with same baud rate.

34

Figure 3.12

3.5.3

Serial COM Port GUI

Multisim

Muiltisim is used to design and create the circuit for the mobile robot and the hand controller.

35

Figure 3.13

Figure 3.14

Circuit for the Mobile Robot

Hand Controller Circuit

36

3.6

Baud Rate Calculation

In order the Bluetooth and the microcontroller communicate, baud rate for both devices have to be same. BlueBee (Bluetooth module) has fixed baud rate 9600. This baud rate has to be same with microcontroller’s UART baud rate .Baud rate for UART can be set by setting a value for SPBRG flag. Calculation for the baud rate of PIC’s UART is shown below: Baud Rate of BlueBee : 9600 bits per second The value of SPBRG = [FOSC/ (baud rate) – 16]/16

(Asynchronous)

(3.1)

= (20MHz/9600 – 16)/16 = 129 FOSC = Oscillation frequency for the microcontroller

3.7

Summary In this chapter, project developments and project implementations are more

emphasis. Project implementation is divided to two categories, hardware implementation and software implementation. In hardware implementation, the details and the functions of the hardware that will use in this project are discussed here. Meanwhile in software implementation section, the software that will be use in this project are discussed.

CHAPTER 4

RESULT AND DISCUSSION

4.1

Result

Mobile robot that used in this project is a two wheeled robot and each wheel is powered by a DC motor. The two wheels are located at back part of mobile robot and a caster in front of mobile robot.

Figure 4.1

Top View of Real Mobile Robot

38

Figure 4.2

Side View of the Real Mobile Robot

Figure 4.3

Bluebee Module Circuit

Figure shows BlueBee circuit. This circuit is connected to the mobile robot circuit. From this circuit, four connections are connected to the main mobile robot circuit. They are Vcc , ground , Rx and Tx. Rx from BlueBee is connected to Tx pin on PIC microcontroller and Tx pin from BlueBee is connected to Rx on PIC microcontroller.

39

UART

Aluminium

Figure 4.4

Hand Controller

The graphical user interface (GUI) is implemented as stated early in Chapter 3. The function of this GUI is to make connection between two different COM ports. Figure show both COM port is connected with same baud rate 9600 bits per second. Bluetooth is connected to COM port 10 meanwhile hand controller is connected to COM port 13.

Figure 4.5

Serial Communications GUI

The expecting result can’t be achieved. The hand controller can’t communicate with the GUI. The data from hand controller can’t be received. So, in the alternative way, laptop keyboard keys are used to control the movement of the mobile robot.

40

Forward

Turn Right

Stop

Turn Left

Backward

Figure 4.6

Alternative Method to Control Mobile Robot

When ‘w’ is pressed

Figure 4.7

Result shown in HyperTerminal after ‘w’ is pressed

41

When ‘x’ is pressed

Figure 4.8

After ‘x’ is pressed

As shown on the figure above, the movement of mobile robot controlled by pressing the keyboard. The mobile robot moved forward when ‘w’ is pressed and moved backward when ‘x’ is pressed.

4.2

Discussion

From this project, controlling the movement of mobile robot with hand controller can’t be achieved. But the mobile robot still can be controlled by using laptop’s keyboard. ‘x’ , ‘s’, ‘a’, ‘d’ and ‘w’ key words used to control the movement of the mobile robot. There is one serious possibility that caused the hand controller can’t be communicating with the GUI. The UC00B (UART device) that connect between the hand controller and the laptop may be spoiled or malfunctioned. It is because two UC00B are replaced during test the hand controller. The UC00B is easily over heated when it is connected to the laptop. Over heated will cause the microchip inside the UC00B malfunctioned or spoiled that will cause it not to work properly.

42

Using low power battery will cause the reaction and performance of the mobile robot reduced. Mobile robot that powered up with Panasonic 9V battery has slow respond and slow movement compare to using 9V Evolta battery that give fast respond and very fast in movement. Using more power battery can increase the performance and the reaction of the mobile robot.

CHAPTER 5

CONCLUSION AND RECOMMENDATION

5.1

Conclusion

The objective of this projects are to controller the mobile robot wirelessly, to establish the Bluetooth connection between the controller and the mobile robot, so the communication of data transmitting and data receiving between the controller and the mobile robot occur wireless and the third objective is to use hand gesture (hand movement) to control the movement of the robot. In the end of this project only first and second objectives can be achieved and the third objective can’t be accomplished. The mobile robot still can be controlled by using Bluetooth and laptop’s keyboard is used as the controller of the mobile robot. The maximum distance that the mobile robot can be controlled from laptop is 10-13 meter in range.

5.2

Recommendation

For the future development, several recommendations are issued to increase the features and performances of the project:

44

i.

Bluetooth module with feature Serial Port Profile (SPP) is used. SPP is a protocol that tries to connect automatically to the host after the connection is break down or unable to connect the host. This protocol has retry attempt up to 1000 times. So if the link between the host and the Bluetooth module is disconnected, the Bluetooth module tries to reconnect automatically with the host.

ii.

The hand controller must be build with Bluetooth module. It will make easier to build a link between the hand controller and the mobile robot. To establish the link between the two Bluetooth modules, one of the Bluetooth modules should be Master and the other one is Slave. If the both are Slave type or Master type, the link can’t be established.

iii.

The mobile robot has to add extra features, so the mobile robot is looks more competitive and more functional. A camera should be added to the mobile robot. The camera will help the user to monitoring the surrounding area that human can be sent. The image of the camera captured can be transmitted to the host by using Bluetooth. Hand griper feature also can be added to the mobile robot. It can used to grip items. These features are very helpful in environment surveillance, rescuing mission and boom refusals purpose.

45

REFERENCE . Available: http://www.swedetrack.com/images/bluet11.htm [Accessed 3/12/2012 2012]. BHAGWAT, P. 2001. Bluetooth : technology for Short Range Wireless Apps. HON, S. L. 2009. Development of a Bluetooth Network based LCD Messaging System. 3-5. JOHNSON, D. Hardware and software implications of creating Bluetooth scatternet devices. AFRICON, 2004. 7th AFRICON Conference in Africa, 17-17 Sept. 2004 2004. 211-215 Vol.1. M. KALIA, S. G., AND R. SHOREY 2000. Efficient Policies for Increasing Capacity in Bluetooth. IBM India Research Laboratory. PEYRARD, F. 2008. Real-time bluetooth communication system for control of a mobile robot. Electrical and Computer Engineering, Canadian Journal of, 33, 63-75. POTTS, J. & SUKITTANON, S. Exploiting Bluetooth on Android mobile devices for home security application. Southeastcon, 2012 Proceedings of IEEE, 15-18 March 2012 2012. 1-4. SUN-MI, J. & NAM-HOON, P. Controlling non IP bluetooth devices in UPnP home network. Advanced Communication Technology, 2004. The 6th International Conference on, 2004 2004. 714-718. YABIN LIU, S. Y., WEIHAI CHEN, WEI LI 2006. IEEE International Conference on Industrial Informations. Wireless Communication Technology Based on Bluetooth and Its Application To a Manipulator, 1251-12. YE, C. & LI, C. Using Bluetooth wireless technology in vehicles. Vehicular Electronics and Safety, 2005. IEEE International Conference on, 14-16 Oct. 2005 2005. 344-347. YE CHEN , L. C. 2005. Using Bluetooth Wireless Technology in Vechicle. YEONG CHE, F., AMIN, S. H. M., BT FISAL, N. & BAKAR, J. A. Bluetooth enabled mobile robot. Industrial Technology, 2002. IEEE ICIT '02. 2002 IEEE International Conference on, 11-14 Dec. 2002 2002. 903-908 vol.2. ZHANG PEI, L. W., WANG JING, WANG YOUZHEN 2000. Bluetooth - The Fastest Developing Wireless Technology. IEEE, 1657-1663.

46

APPENDIX A Mobile Robot Coding //include //=========================================================== #include #include "system.h" #include "uart.h" // Configuration //=========================================================== __CONFIG(HS & // External Crystal at High Speed WDTDIS & // Disable Watchdog Timer. PWRTEN & // Enable Power Up Timer. BORDIS & // Disable Brown Out Reset. MCLREN & // MCLR function is enabled LVPDIS); // Disable Low Voltage Programming. unsigned int data=0; ////defineport ////motor speed // #define speedr CCPR1L #define speedl CCPR2L // //// MOTOR DIRECTION #define mr1 #define mr2

RD0 RD1

#define ml1 #define ml2

RD3

RD2

////=====declaration of prototype================================== void init(void); void forward(unsigned int i); void backforward(unsigned int i); void turn_left(unsigned int i,unsigned int j); void turn_right(unsigned int i,unsigned int j); void stop(void);

47

//main function //========================================================== void main(void) { PORTA = 0; // Clear Port PORTB = 0; PORTC = 0; PORTD = 0; TRISA = 0b00000000; // set PORTA as INPUT TRISB = 0b00000000; // set PORTB as OUTPUT , PORTB as INPUT TRISC = 0b10000000; TRISD = 0b00000000; // set PORTD as output ANSELH = 0; // SET PORTB as DIGITAL I/O for PIC16F887 init(); uart_initialize(); Initialise UART while (1) { uc_uart_receive(); // UART receive data data = RCREG; // receive data from uart and save at data if (data == 'w') // moving forward { forward(253); uart_putstr("Mobile RoBot moving forward!!"); } else if (data=='a')// turn left { uart_putstr("Mobile RoBot moving left!!"); turn_left(200,250); } else if (data=='d')// turn right { uart_putstr("Mobile RoBot moving right!!"); turn_right(250,150); } else if ( data=='s')//stop

//

48

}

}

{ uart_putstr("Mobile RoBot stoped!!"); stop(); } else if ( data=='x')// backward { uart_putstr("Mobile RoBot moving backward!!"); backforward(250); }

void init(void) //initialize { PR2=255; CCP1CON=0b00001100;//pwm mode CCP2CON=0b00001100; T2CON=0b00000110; T1CON=0b00000000; CCPR1L=CCPR2L=0; } //=======================forward======================= void forward(unsigned int i) { speedr=speedl=i; PORTD=0b000000101; // // // // }

mr1=1; mr2=0; ml1=0; ml2=0;

//move forward //move forward

//=======================backforward========================= void backforward(unsigned int i) { speedr=speedl=i; mr1=0; //move bforward mr2=1; ml1=0; //move bforward ml2=1;

49

} ////=======================turn_left========================= void turn_left(unsigned int i,unsigned int j) { speedl=i;speedr=j; // mr1=0; //move forward // mr2=0; // ml1=1; //move forward // ml2=0; //PORTD=0b00000100; mr1=1; //move forward mr2=0; ml1=0; //move forward ml2=0; } ////=======================turn_right========================== void turn_right(unsigned int i,unsigned int j) { speedl=i;speedr=j; mr1=0; //move forward mr2=0; ml1=1; //move forward ml2=0; } ////=======================break_stop function========== void stop(void) { speedl=0; speedr=0; } void uart_initialize(void) { unsigned char dummy = 0; BRG16 = 0; SYNC = 0; TX9 = 0; RX9 = 0; BRGH = 1; SPBRG = 129; SPEN = 1; CREN = 1; TXEN = 1; dummy = RCREG;

// Select high speed baud rate. // Configure the baud rate. // Enable serial port. // Enable reception. // Enable transmission. // dummy read, to clear the receive buffer

50

}

dummy = RCREG;

void uart_transmit(unsigned char uc_data) { // Wait until the transmit buffer is ready for new data. while (TXIF == 0);

}

// Transmit the data. TXREG = uc_data;

unsigned char uc_uart_receive(void) { // If there is overrun error... if (OERR == 1) { // Clear the flag by disable and enable back the reception. CREN = 0; CREN = 1; } // Wait until there is data available in the receive buffer. while (RCIF == 0);

}

// Return the received data. return RCREG;

void uart_putstr(const char* csz_string) { // Loop until the end of string. while (*csz_string != '\0') { uart_transmit(*csz_string);

}

}

// Point to next character. csz_string++;

51

APPENDIX B Hand Controller Coding

// include //==================================================== #include #include // configuration //==================================================== __CONFIG ( 0x3F32 ); //configuration for the microcontroller // function prototype (every function must have a function prototype) //================================================= void delay(unsigned long data); unsigned char uart_rec(void); void uart_send(char data); void uart_str(const char *s);

//receive uart value

void send_cmd(unsigned char num, unsigned int data, unsigned int ramp); // main function (main fucntion of the program) //======================================================= void main() { unsigned long delay_time=5000; unsigned int a=0; unsigned int b=0; //set I/O input output TRISB = 0b11111111; TRISD = 0b00000000; TRISA = 0b111111;

//configure PORTB I/O direction //configure PORTD I/O direction //configure PORTA I/O direction

//Configure UART SPBRG=129; BRGH=1; TXEN=1; TX9 =0; RX9 =0;

//set baud rate as 9600 baud //baud rate high speed option //enable transmission //8-bit transmission //8-bit reception

52

CREN=1; SPEN=1;

//enable reception //enable serial port

//setup ADC ADCON1 = 0b00000110; CMCON = 0b00000110;

//set ADx pin digital I/O

//PORTB=0b11111000; while(1) { //uart_str("kesava"); b=PORTB; if ( b == 0b00000001) { uart_str("1"); }

// display on HyperTerminal

else if ( b == 0b00000010) { uart_str("2"); } if(b==0b00000000) { uart_str("s"); } else if(b==0b10000000) { uart_str("w"); } else if (b == 0b11110000) { uart_str("x"); } else if (0b11001000) { uart_str("d"); } else if (b == 0b00001000) { uart_str("a"); } }

}

// display on GUI

// display on GUI

// display on GUI

53

// functions //====================================================== void delay(unsigned long data) //delay function, the delay time { //depend on the given value for( ;data>0;data--); }

unsigned char uart_rec(void) { unsigned char rec_data; while(RCIF==0); rec_data = RCREG; return rec_data; } void uart_send(unsigned char data) { while(TXIF==0); TXREG=data; } void uart_str(const char *s) { while(*s)uart_send(*s++); }

//receive uart value //wait for data //return the data received

//only send the new data after //the previous data finish sent

54

APPENDIX C Program of Serial Communication Graphical User Interface (GUI)

Imports System Imports System.ComponentModel Imports System.Threading Imports System.IO.Ports Public Class frmMain Dim myPort As Array 'COM Ports detected on the system will be stored here Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'When our form loads, auto detect all serial ports in the system and populate the cmbPort Combo box. myPort = IO.Ports.SerialPort.GetPortNames() 'Get all com ports available cmbBaud.Items.Add(9600) 'Populate the cmbBaud Combo box to common baud rates used cmbBaud.Items.Add(19200) For i = 0 To UBound(myPort) cmbPort.Items.Add(myPort(i)) Next cmbPort.Text = cmbPort.Items.Item(0) 'Set cmbPort text to the first COM port detected cmbBaud.Text = cmbBaud.Items.Item(0) 'Set cmbBaud text to the first Baud rate on the list btnDisconnect.Enabled = False

'Initially Disconnect Button is Disabled

End Sub Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click SerialPort1.PortName = cmbPort.Text 'Set SerialPort1 to the selected COM port at startup SerialPort1.BaudRate = cmbBaud.Text 'Set Baud rate to the selected value on

55

'Other Serial Port Property SerialPort1.Parity = IO.Ports.Parity.None SerialPort1.StopBits = IO.Ports.StopBits.One SerialPort1.DataBits = 8 'Open our serial port SerialPort1.Open() btnConnect.Enabled = False btnDisconnect.Enabled = True

'Disable Connect button 'and Enable Disconnect button

End Sub Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click SerialPort1.Close() 'Close our Serial Port btnConnect.Enabled = True btnDisconnect.Enabled = False End Sub Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click SerialPort1.Write(txtTransmit.Text & vbCr) 'The text contained in the txtText will be sent to the serial port as ascii 'plus the carriage return (Enter Key) the carriage return can be ommitted if the other end does not need it End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the serialPort End Sub Private Sub ReceivedText(ByVal [text] As String) 'compares the ID of the creating Thread to the ID of the calling Thread If Me.rtbReceived.InvokeRequired Then Dim x As New SetTextCallback(AddressOf ReceivedText) Me.Invoke(x, New Object() {(text)}) Else Me.rtbReceived.Text &= [text] End If End Sub

56

Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged If SerialPort1.IsOpen = False Then SerialPort1.PortName = cmbPort.Text 'pop a message box to user if he is changing ports Else 'without disconnecting first. MsgBox("Valid only if port is Closed", vbCritical) End If End Sub Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBaud.SelectedIndexChanged If SerialPort1.IsOpen = False Then SerialPort1.BaudRate = cmbBaud.Text 'pop a message box to user if he is changing baud rate Else 'without disconnecting first. MsgBox("Valid only if port is Closed", vbCritical) End If End Sub End Class