Getting Started with PDA to Bluetooth communication.
This example will show you how to use a POCKET PC with built-in bluetooth
hardware to send serial data to a BLUESMIRF bluetooth module. The BLUESMIRF
will send the received serial data to a host CPU. The host CPU will pass the received
data to an external CPU when it is requested to do so.
The PDA used in this example is an HP IPAQ H2210 Pocket PC.
The host CPU used in this example is an ATHENA microcontroller.
The external CPU used in this example is a Personal Computer running Windows XP.
The application software for the Pocket PC was written in the BASIC programming
language using the Basic4ppc compiler for the POCKET PC.
The microcontroller code for the ATHENA was written in BASIC using the Kronos
Robotics Athena Editor software Version 2.0.9 which runs on Windows XP.
This example will show you how to establish a bluetooth connection between the
POCKET PC and the BLUESMIRF bluetooth module. The application software
will open a Serial COM Port and send serial data using the PDA's built-in bluetooth
hardware to the external BLUESMIRF bluetooth module.
The BLUESMIRF module is shipped with factory default configuration settings. In this
example we want to use these factory default settings straight out of the box and not have to
change any of them to use the BLUESMIRF module.
One of the factory default settings is "Long Response" mode. When the BLUESMIRF
performs a specific task it will send a response ( which is a string of characters ) out its TX pin
to the host CPU to let it know what has happened. In this example, we have to deal with the
following actions:
COM Port Open
COM Port Closed
When the POCKET PC PDA application software Opens a COM Port the BLUESMIRF
module will send a string of characters to the host CPU.
When the POCKET PC PDA application software Closes a COM Port the BLUESMIRF
module will send a string of characters to the host CPU.
The BLUESMIRF module that I have sends the following strings to the host CPU:
COM Port Open: ( The BLUESMIRF module will send the string )
CONNECT,00043E431B14
COM Port Closed: ( The BLUESMIRF module will send the string )
DISCONNECT
The diagram below shows the steps needed to send serial data from the POCKET PC
PDA to the BLUESMIRF Module to the External CPU.
The following program statement in the ATHENA microcontroller code will read every byte of data
that is sent to the ATHENA by the BLUESMIRF module.
loop1: serin loop1,0,a
When the Serial COM Port is Opened or Closed the above line of ATHENA program code will read in
each byte that is recieved from the BLUESMIRF module and store the received bytes, one right after the
other, in the variable "a". Each byte in the string will be read and stored in the variable "a", the ATHENA
will read in the entire string that is sent to it by the BLUESMIRF module. The bytes in the string will be
ignored since the ATHENA will not process or store any of the bytes. By using a Flag variable and 2 special
characters, we can control when we want the ATHENA to actually look at and process the bytes that it
receives from the BLUESMIRF module.
ATHENA Microcontroller Program Code.
'A sample program written for the ATHENA microcontroller
'which will recieve serial data sent from the POCKET PC
'to the BLUESMIRF module across the Bluetooth wireless
'link. After the BLUESMIRF module has received the serial
'data it will be sent to the ATHENA microcontroller. The
'ATHENA will send the serial data it receives to the
'ATHENA DEBUG TERMINAL software running on the PC.
'The KRONOS ROBOTICS ATHENA EDITOR Version 2.0.9 was
'used to Write the program code, Test, Debug and Program
'the compiled code into the ATHENA microcontroller.
'Dimension the variables used by the program.
dim a,s2cpu
'Initialize the Send to Cpu Flag equal to Zero.
'When this Flag = 0 No data will be passed to the
'external CPU. When this Flag = 1 data will be
'passed to the external CPU.
s2cpu=0
'Initialize Port Pin 0 as an Input. Serial data
'received by the BLUESMIRF module from the POCKET
'PC PDA across the Bluetooth connection will be
'received by the ATHENA microcontroller at its
'Port Pin 0. The TX line of the BLUESMIRF module
'is physically wired to Port Pin 0 of the ATHENA.
input 0
'Set the Baud rate on the ATHENA to 9600:N:8:1
setbaud SBAUD9600
'The following line of code will read the serial data
'being sent to Port Pin 0 of the ATHENA. If no data
'is currently being received at Port Pin 0 then program
'control will jump back to the label ( loop1 ). This
'program statement will continually jump back to label
'( loop1 ) until an 8-bit byte is received a Port Pin 0.
'When an 8-bit byte is received at Port Pin 0, the
'received character byte will be stored in the program
'variable ( a ) and program execution will fall through
'to the next line of program code.
loop1: serin loop1,0,a
'If the application running on the POCKET PC PDA sends
'the special character ( * ) then set the ( s2cpu ) flag = 1.
'This will tell the ATHENA to send the received 8-bit
'character byte to the external CPU. In this example
'the external CPU is a Personal Computer. Once the
'( s2cpu ) flag has been set equal to 1, then jump back
'to program label ( loop1 ) to receive the next byte.
if a=42 then
s2cpu=1
goto loop1
endif
'If the application running on the POCKET PC PDA sends
'the special character ( ^ ) then set the ( s2cpu ) flag = 0.
'This will tell the ATHENA not to send the received 8-bit
'character byte to the external CPU. In this example
'the external CPU is a Personal Computer. Once the
'( s2cpu ) flag has been set equal to 0, then jump back
'to program label ( loop1 ) to receive the next byte.
if a=94 then
s2cpu=0
goto loop1
endif
'If the (s2cpu) flag equals 1 then send the byte received
'to the external CPU. In this example the program statement
'( print a ) will send the received byte to the Personal
'Computer which will display the character in the ATHENA
'DEBUG TERMINAL. After sending the received byte to the
'Personal Computer, program control will jump back to
'program label ( loop1 ).
if s2cpu=1 then
print a
endif
goto loop1