Page 67 - The Definitive Guide to Building Java Robots
P. 67

Preston_5564C02.fm  Page 48  Wednesday, September 14, 2005  5:42 AM



                 48     CHAPTER 2  ■  SERIAL COMMUNICATION

























                        Figure 2-10. DLink DBT-120 USB Wireless Bluetooth Adapter


                        Code Objectives
                        The objectives for this code are to:
                            • Demonstrate a wireless serial connection

                            • Show that a serial connection is the same as a wired one with the proper software
                              installed on the Stamp


                        Code Discussion
                        The Bluetooth board connected to our BOE (Board of Education) will communicate directly to
                        our PC via one of its serial connections. While our PC will not notice any difference, there are
                        some slight changes that have to be made on the Stamp side.
                            First, some initialization commands need to be sent to the EB500, along with the address
                        of our USB Bluetooth adapter on the PC. Once it’s connected, our program looks very much
                        like the original with the exception of the SEROUT pin and the SERIN pin: pin 1 versus pin 16.
                            The Java code is the same code as that used earlier in Example 2-4. Just change the port ID
                        to match the Bluetooth adapter and you are set. (See Example 2-14.)


                        Example 2-14. BluetoothStamp.bs2
                        ' {$STAMP BS2}
                        serialin     VAR   Byte
                        INPUT 5
                        PAUSE 1000
                        SEROUT 1,84, ["con 00:11:95:4F:54:39",CR]
                        SERIN 0,84,[WAIT("ACK",CR)]
                        WaitForConnection:
                          IF IN5 = 0 THEN WaitForConnection
   62   63   64   65   66   67   68   69   70   71   72