Hardware Reference
In-Depth Information
Verifying the Code
The Firmata sketch is uploaded to the Arduino and the XBees are both plugged into the computer and Arduino.
This configuration of the modules is in transparent mode, and the Firmata test app can now communicate with the
Arduino. It is optional to add a few buttons, servos, or LEDs to explore the application's potential, or use the examples
created in Chapter 3. If the modules are not communicating, check the connections, settings, and selected COM port.
You can make computer-to-computer chat possible with the XBee's transparent mode and serial terminals by
connecting the XBee serial adapter to pins 2 and 3 of the arduino and loading the software serial sketch onto the arduino,
changing the baud rates in the sketch to match the XBee module.
Note
API Mode
API mode is the alternative to AT command mode. The API that is implemented with the XBee module allows
programs to change internal settings, create direct routing, discover new nodes, and push remote AT commands or
firmware updates, along with other advanced control options. This mode uses packets that are referred to as frames in
the XBee data sheet.
There are currently 18 different frame types for series 2 modules; the first 4 bytes of the frame are always the same
type of information, as described in Figure 5-2 .
Figure 5-2. API packet structure
0x7E to show that a frame is starting,
The first byte of the frame is always
The next two bytes are the length of the data contained in the frame; this number is the total
bytes from the fourth byte to the checksum.
Byte 4 is the frame type; this describes the data that makes up the data section of the frame,
notifying a program how to interpret the data. The frame data is specific to the frame
type. The structure is outlined for the various frames in the “API Operation” section of the
XBee data sheet; the series 2 data sheet is available at http://ftp1.digi.com/support/
documentation/90000976_K.pdf .
The last byte of the frame is the checksum and is calculated by subtracting the total value
of bytes from the frame type to the last byte of the frame data from 0xFF . This calculation is
done within a single byte, and any value above 255 is truncated. The checksum is used by
the modules to help determine that the frame is formed properly before sending and can be
used by the program to determine that the data received is the proper data. The frame may be
malformed when a verification frame is not returned or the when frame ID byte is set to zero.
The frame ID is usually the first byte of the frame data section of the frame; this is to determine
what frame is being talked about when information frames are returned. The frame ID is also
useful for sequential frames to determine the order when receiving frames.
 
 
Search WWH ::




Custom Search