Hardware Reference
In-Depth Information
If you're using Mac OS X, choose the Apple menu System
Preferences, then click Bluetooth. Make sure Bluetooth
is turned on and Discoverable, and click "Show Bluetooth
status in the menu bar." At the bottom of the list of
devices, click the + sign to launch the Bluetooth Setup
Assistant. The computer will search for devices and
find one called FireFly-XXX (Bluetooth Mate Gold) or
RN42-XXX (Silver), where XXX is the Bluetooth module's
serial number. If you have no other Bluetooth devices on,
it will be the only one. Choose this device, and on the next
screen, click Passkey Options. Choose "Use a Specific
Passcode," and enter 1234 . Click Continue. A connection
will be established, as will a serial port. When you look for
the serial port in CoolTerm, the Arduino serial port menu,
or the Processing serial port list, it will be FireFly-XXX-SPP
or RN42-XXX-SPP .
Ubuntu Linux's Bluetooth manager for version 1.0 is a bit
limited, so it's easier to install BlueMan instead. Go to the
Ubuntu Software center, search for BlueMan, and install
it. When it's installed, open the System control panel and
you'll see Bluetooth Manager, in addition to the default
Bluetooth control panel. Open Bluetooth Manager, and it
will scan for available devices and show them, including
one called FireFly-XXX or RN42-XXX , where XXX is the
serial number of your Bluetooth module. When prompted
for the device's pairing code, enter 1234 . Once it's added,
click Setup, and you'll get a dialog asking you if you want
to connect to a serial port. Click Forward, and it will tell you
the name of the serial port for the Bluetooth module, /dev/
rfcomm0.
Adjusting the Monski Pong Program
Once your computer has made contact with the Bluetooth
module, you can connect to it like a serial port. Run the
Monski Pong Processing sketch and check the list of serial
ports. You should see the new port listed along with the
others. Take note of which number it is, and change these
lines in the setup() method:
For Windows 7 users, there are different Bluetooth radios
in different Windows-based PCs. If your PC doesn't have
a built-in Bluetooth radio, any Bluetooth adapter that
supports the Windows Bluetooth Stack will do. Most
Bluetooth USB dongles on the market support it. Install
the drivers according to your radio's instructions, and
when it's done, click on the Show Hidden Icons icon in the
taskbar (the small triangle in the lower-right-hand corner).
When you do, you'll see the Bluetooth Devices icon, as
shown in Figure 2-15. Click on this to add a new Bluetooth
Device.
String portName = Serial.list()[0];
// open the serial port:
myPort = new Serial(this, portName, 9600);
For example, if the Bluetooth port is the ninth port in your list,
change the first line to open Serial.list[8] . Then change the
data rate in the second line as follows:
myPort = new Serial(this, portName, 115200);
If you plug or unplug any serial devices after you
do this, including the Arduino, you'll need to quit and
restart the Processing program, as the count of serial ports
will have changed.
!
Figure 2-15
Where to find the Windows Bluetooth Devices icon (it's well hidden!).
Click Customize... if you want to add it to your taskbar.
Likewise, you'll need to change your Arduino sketch so that
the Serial.begin() line reads as follows:
The system will search for new devices and present you
with a list, which should include one called FireFly-XXX ,
where XXX is the serial number of your Bluetooth module.
If you have no other Bluetooth devices nearby, it will be the
only one. When prompted for the device's pairing code,
enter 1234 . This step will add a new serial port to your
list of serial ports. Make note of the port name (mine is
COM14) so you can use it later.
Serial.begin(115200);
Disconnect the Bluetooth module from the Arduino before
you upload the modified sketch, as it will interfere with the
upload. You can re-connect it once you've uploaded the new
code. With no other changes in code, you should now be
able to connect wirelessly. Monski is free to roam around
the room as you play pong. When the Processing program
makes a connection to the Bluetooth module, the green
LED on the module will turn on.
 
Search WWH ::




Custom Search