Hardware Reference
In-Depth Information
Bluetooth Transceivers
In Chapter 2, you learned how to connect
a microcontroller to your personal
computer using a Bluetooth radio. This
example shows you how to connect two
microcontrollers using Bluetooth in a
similar manner.
MATERIALS
» 2 solderless breadboards
» 1 uSb-to-TTL serial adapter
» 2 Arduino modules
» 2 bluetooth Mate modules
» 2 potentiometers or other analog sensors
» 2 LEDs
» 2 220-ohm resistors
» 2 10-kilohm resistors
» 2 pushbuttons
As mentioned in Chapter 2, Bluetooth was originally
intended as a protocol for replacing the wire between
two devices. As a result, it requires a tighter connection
between devices than you saw in the preceding XBee
project. In that project, a radio sent out a signal with no
awareness of whether the receiver got the message, and
it could send to a different receiver just by changing the
destination address. In contrast, Bluetooth radios must
establish a connection before sending data over a given
channel, and they must break that connection before
starting a conversation with a different radio over that
channel. The advantage of Bluetooth is that it's built into
many commercial devices today, so it's a convenient
way to connect microcontroller projects to personal
computers, phones, and more. For all its complications, it
offers reliable data transmission.
USB-to-serial modules shown for Project 4, Negotiating in
Bluetooth in Chapter 2, but the goal of this project is to get
two microcontrollers talking to each other over Bluetooth
with no personal computer in the middle. So, instead of
using the USB-to-Serial adapter, you can set up an Arduino
board to pass the serial data from your computer to a
Bluetooth radio. Then, when you're ready to remove the
personal computer in Step 3, you'll just have to change the
sketch and make a minor circuit change to remove the PC.
To set up an Arduino as a USB-to-Serial passthrough, first
program the Arduino with a blank sketch. The BareMini-
mum sketch from the Basics examples will do fine. It looks
like this:
The modules used here—the Bluetooth Mate radios
from Spark Fun—use a radio from Roving Networks. The
command set used here was defined by Roving Networks.
Other Bluetooth modules from other manufacturers use
command sets with a similar style, and they may execute
similar functions, but their syntax is not the same. Unfor-
tunately, Bluetooth radio manufacturers haven't set a
standard syntax for their devices.
void setup() {
}
void loop() {
}
When you upload this sketch, the microcontroller will do
nothing, so you can use its connection to the USB-to-
serial processor to communicate with the Bluetooth radio.
Connect the radio as shown on the left (we'll call it Arduino
#1 and radio #1) in Figure 6-20; then, connect it to your
computer and using your serial terminal program, open a
serial connection to it at 115200 bits per second.
Step 1: The Circuits
Instead of pairing a Bluetooth radio with your computer's
Bluetooth radio as you did in Chapter 2, you're going to
pair two radios attached to microcontrollers. When you're
done, your computer won't be needed.
For the moment, you'll use the second Arduino just to
send a simple message so you can see things are working.
Connect it to the second Bluetooth Mate using the circuit
shown at right in Figure 6-20 (we'll call it Arduino #2 and
radio #2). Eventually, they will both be wired this way.
Because the Bluetooth connection process involves
many steps, it's easiest to learn and understand it using
a serial terminal program before you start to write code.
Even when you are programming, the serial terminal
program will be a useful diagnostic tool. You can use the
Search WWH ::




Custom Search