Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Practical Example
Minimum parts needed: (see Tom Igoe's parts list for additional details)
Step 1:
Solder the XBee RF Module to the PCB breakout board as shown. The white silkscreened lettering should face
downward, away from the XBee Module. Be sure to leave enough space so that the headers do not touch the back of the
module.
faludi.com/…/XBee_example.html 1/5
10/03/2011 XBee Example
XBee soldered to custom breakout board. Be sure to leave enough space between the
XBee and the metal headers so that they don't touch and short out.
Step 2:
Set up two breadboards with a PIC on each. You'll need to add a 3.3 Volt regulator to each board, for powering the XBee
radios. The 3.3V regulator used in this example is arranged (from left to right) Ground-Output-Input, which is different from
the 5 Volt one.
Step 3:
Connect 3.3 Volt power to pin 1 of the XBee, ground to pin 10, RC7 from the PIC to pin 2 and RC6 to pin 3 as shown.
You may also want to add LEDs to pins 6, 13 and 15 for some status feedback.
faludi.com/…/XBee_example.html 2/5
10/03/2011 XBee Example
XBee connected to 3.3 Volt power and common ground. The XBee tx pin is connected to rx on PIC, and XBee rx pin is connected to tx on PIC.
Green LED shows that XBee is powered on and not in sleep mode, yellow LED flashes except when
in AT command mode, and red LED lights when receiving RF data from another XBee radio.
Step 4:
' for some reason it seems to help to send an arbitrary character first
' then pause for the guard time before requesting command mode
serout2 portc.6, true9600, ["X"]
pause 1500
' wait for a response from the XBee for 2000 ms, or start
' over at the configure label if no valid response comes
SERIN2 portc.7, true9600, 2000, configure, [WAIT ("OK")]
' wait for a response from the XBee for 2000 ms, or start
' over at the configure label if no valid response comes
SERIN2 portc.7, true9600, 2000, configure, [WAIT ("OK")]
main:
' convert it to a readable ASCII value, send it out the serial port:
serout2 portc.6, true9600, [DEC thisByte]
goto main
Step 5:
' set a constant for timeout while waiting for serial input
timeout CON 2000
' for some reason it seems to help to send an arbitrary character first
' then pause for the guard time before requesting command mode
serout2 portc.6, true9600, ["X"]
pause 1100
' wait for a response from the XBee for 2000 ms, or start
' over at the configure label if no valid response comes
SERIN2 portc.7, true9600, timeout, configure, [WAIT ("OK")]
' wait for a response from the XBee for 2000 ms, or start
' over at the configure label if no valid response comes
SERIN2 portc.7, true9600, timeout, configure, [WAIT ("OK")]
main:
goto main
Step 6:
Attach a switch to RB0 of the sending board, and an LED to RB1 of the receiving board. Close the switch and the LED
should light up.
Step 7:
Change your code so that there's a switch and light on both boards, and closing either switch lights the light on the other
board. This should help familiarize you with how the radios communicate.
There's PLENTY more features on the XBee including broadcast modes, data enveloping and mesh networking. Once
you're comfortable with the basics, you may want to explore further.
faludi.com/…/XBee_example.html 5/5