I am trying to get an Arduino connected to an xBee (Series 2) to send a remote command to another xBee, and get it's I/O pin to blink the LED.
The hardware setup is trivial:
The Arduino ground and 3.3v pins are connected to the coordinator's gnd (Pin 10) and Vcc (1) pins respectively, Arduino pin 5 goes to Din (3), pin 6 goes to Dout (2).
The remote xbee is connected to power and ground, and D0 (pin 20) is connected to an LED through a 150 Ohm resistor.
The firmware setup is right out of Faludi's book - coordinator set to API mode, DH and DL set to the remote xBee's. I've tried both 1 and 2 for API enable. Since I'm not using the xBee library, not sure which one is correct. Remote xbee is setup as a router in AT mode, D0 is set to 4 (low digital).
When I put the coordinator into a USB explorer and fire up the Processing sketch from the Faludi book for the Simple Actuator Network (the one with the swtches) - it works fine - flipping the switch on the screen turns the LED on and off. So I believe the xBees are configured properly.
Here's my Arduino sketch:
#include <NewSoftSerial.h>
NewSoftSerial xbeeser(6,5); //receive, then transmit
void setup()
{
Serial.begin(57600);
Serial.println("Activating");
xbeeser.begin(4800);
}
void loop()
{
PulsePin('0', xbeeser, 500);
delay(1000);
}
void PulsePin(int PinNumber, NewSoftSerial xbeeSer, int delaytime)
{
Serial.println("Sending On Command");
setRemoteState(PinNumber, 0x4, xbeeSer); //turn on
delay(delaytime);
Serial.println("Sending Off Command");
setRemoteState(PinNumber, 0x5, xbeeSer); //turn off
}
void setRemoteState(int pinnumber, int value, NewSoftSerial xbeeSer)
{
SendByteToXBee(0x7E, xbeeSer); //start byte
SendByteToXBee(0x0, xbeeSer); //high part of length
SendByteToXBee(0x10, xbeeSer); //low part of length
SendByteToXBee(0x17, xbeeSer); //remote AT command
SendByteToXBee(0x0, xbeeSer); //frame ID (no reply)
// 64bit of recipient of recipirnt, or 0xFFFF for broadcast
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0x00, xbeeSer);
SendByteToXBee(0xFF, xbeeSer);
SendByteToXBee(0xFF, xbeeSer);
//16 bit of recipient, or 0xFFFE if unknown
SendByteToXBee(0xFF, xbeeSer);
SendByteToXBee(0xFE, xbeeSer);
SendByteToXBee(0x02, xbeeSer); //apply changes immediately
SendByteToXBee('D', xbeeSer); //command name in ASCII
SendByteToXBee(pinnumber, xbeeSer); //command name in ASCII
SendByteToXBee(value, xbeeSer); //turn on or off
//checksum
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + pinnumber + value;
SendByteToXBee(0xFF - (sum & 0xFF), xbeeSer); //calculate checksum
delay(10);
Serial.println("");
}
void SendByteToXBee(byte Data, NewSoftSerial xbeeSer)
{
Serial.print(Data, HEX);
Serial.print(" : ");
xbeeSer.print(Data, BYTE);
}
Checking the serial monitor, I'm getting the expected results being printed to the screen. But there's no action from the LED at all (the LED is good - connecting it to power lights it right up).
I tried hooking up the arduino with the above sketch to a second arduino set up to just pipe everything from a NewSoftSerial input to the Serial output (just piping from the software serial port to the hardware serial port), and it shows that the data is being correctly sent. So the problem has to be either in my xBee setup (unlikely, as it works with the Processing sketch), or with the way I put together the request frame.
Any advice on what I'm doing wrong would be greatly appreciated.
PS: Here's what I'm seeing on the serial monitor:
Activating
Sending On Command
7E : 0 : 10 : 17 : 0 : 0 : 0 : 0 : 0 : 0 : 0 : FF : FF : FF : FE : 2 : 44 : 30 : 4 : 73 :
Sending Off Command
7E : 0 : 10 : 17 : 0 : 0 : 0 : 0 : 0 : 0 : 0 : FF : FF : FF : FE : 2 : 44 : 30 : 5 : 72 :
Sending On Command
7E : 0 : 10 : 17 : 0 : 0 : 0 : 0 : 0 : 0 : 0 : FF : FF : FF : FE : 2 : 44 : 30 : 4 : 73 :
Sending Off Command
7E : 0 : 10 : 17 : 0 : 0 : 0 : 0 : 0 : 0 : 0 : FF : FF : FF : FE : 2 : 44 : 30 : 5 : 72 :