Example 3: How to Use
Analog I/O Communications
In addition to accepting logic-0 and logic-1 logic signals,
the ADx-DIOx pins can handle analog voltages too, but with
constraints. Each XBee module contains a 10-bit analog-to-digital converter (ADC) that “converts” a voltage into a
10-bit binary value. In hexadecimal, those values range from
000 to 3FF, or 0 to 1023 in decimal. Keep in mind that the
ADC requires a reference voltage input at the VREF pin
(pin 14). You could connect this pin to 3. 3 volts, although a
commercial 2. 5 volt reference chip would work well too,
and would give the ADC inputs a range from zero to
2. 5 volts. The ADC input voltage can go from zero volts
(ground) to as high as the reference voltage, VREF. The
ADC input and the VREF input (pin 14) should never exceed
3. 3 volts.
On a transmitting module, only the AD0-DIO0 and
AD1-DIO1 analog input pins have corresponding “analog”
outputs on a receiving module. Those two outputs —
PWM0 (pin 6) and PWM1 (pin 7) — produce a pulse width
modulation (PWM) signal. The PWM outputs have a fixed
frequency of 16 kHz. The width of the pulse varies in direct
proportion to the voltage on the corresponding AD0-DIO0
or AD1-DIO1 inputs at the transmitter.
These two PWM outputs have some quirks. If you
sample the voltage at the transmitter’s AD0-DIO0 or
AD1-DIO1 pins every few seconds and transmit the
information every few seconds, the PWM output
operates just fine. However, you
cannot send only one analog
sample and have the PWM output
continue to produce the same
signal forever. The PWM output
stays active for only about 22 to
25 seconds.
If you drive an LED at your
LOCAL module with the PWM0 or
PWM1 signal, varying the voltage at
the corresponding AD0-DIO0 or
AD1-DIO1 input at your REMOTE
module will vary the LED brightness.
The settings shown in Table 2
configure the LOCAL and REMOTE
modules for this type of use. Note
that the REMOTE module samples its
analog input (AD0-DIO0) once every two seconds (3E8 x 2).
Figure 5 shows the XBee module connections. If you need
a voltage from an XBee PWM output, say PWM0, you can
use a simple R/C circuit to filter the pulsing signal to give
you a DC signal. This PWM0 output will correspond to the
analog input at the transmitter’s AD0-DIO0 input. Again,
every few seconds a transmitting module with an analog
input must transmit — a “refresh” — the analog information
to the receiving module with an active PWM output.
Otherwise, the PWM output will cease after 22-25 seconds.
Table 2. XBee module settings for an analog input
and PWM output.
LOCAL REMOTE
DL 12AB
MY FE54
D0-DIO0 2-ADC
IT 1
IR 7D0
IA FFFF
NI REMOTE
*Look in the "I/O Line Passing" folder in the Modem Configuration window.
DL
MY
P0-PWM0
IA*
NI
FE54
12AB
FIGURE 5. An XBee circuit that uses an analog input
at a remote module to control a PWM output that drives an LED.
Example 4: How to Obtain
ADC Values
If you set any of the AD2-DIO2 through AD6-DIO6 pins
on an XBee module to measure voltages and transmit this
information, the 10-bit ADC values appear in the serial
output from the receiver’s UART Data Out (pin 2). A
microcontroller can accept this serial data and software can
process it to yield useful information. You also can view the
data in the X-CTU Terminal window.
I set my REMOTE module to have an active digital input
at AD2-DIO2 (pin 18) and an active analog input at AD4-
DIO4 (pin 11). A 10K ohm potentiometer provided a
voltage that varied between ground and + 3. 3 volts, and a
jumper served as my digital input “switch.” The REMOTE
module took one sample every five seconds and transmitted
it to my LOCAL module. The schematic diagram in Figure 6
shows the electrical connections. To illustrate the
communication of ADC data, I set the configurations shown
in Table 3 for my REMOTE and LOCAL XBee modules.
SERVO 01.2013 47