Home/Support/Support Forum/Xbee s2 writing to a digital pin to multiple routers individually

Xbee s2 writing to a digital pin to multiple routers individually

0 votes
Hey. I am working with Xbee s2 and s2c and I am trying to find a way how to write digital high/low to multiple remote Xbee router devices.

int led = 13;

void setup(){
pinMode(led, OUTPUT);
Serial.begin(9600);
}

void loop(){
digitalWrite(led, HIGH);
setRemoteState(0x5);
delay(5000);
digitalWrite(led, LOW);
setRemoteState(0x4);
delay(5000);
}

void setRemoteState (char value){
Serial.write(0x7E); //start byte
Serial.write((byte)0x0); //high part of length (always zero)
Serial.write(0x10); //low part of length
Serial.write(0x17); //0x17 is remote AT command
Serial.write((byte)0x0); //frame ID set to zero for no reply

//ID of recipient, or use 0xFFFF for broadcast
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write((byte)0x0);
Serial.write(0xFF);
Serial.write(0xFF);

//16 bit of recipient of 0xFFFE

Serial.write(0xFF);
Serial.write(0xFE);

Serial.write(0x02);

Serial.write('D');
Serial.write('4');


//command data in as many bytes
Serial.write(value);

//checksum
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '4' + value;
Serial.write(0xFF - (sum & 0xFF));
}

I am using the following code and I am able to toggle the D4 pin of my router xbee device. I have connected another Xbee router device with the same PAN ID and its D4 is also toggling.

My question is how do I address them independently? I would like to choose which one do I want to toggle first and then delay till I toggle the second one?

I can identify the serial number high and low addresses of each router device and I have tried changing the following part of the code with the serial adress
Serial.write((byte)0x0); >>> 0x00
Serial.write((byte)0x0); >>> 0x13
Serial.write((byte)0x0); >>> 0xA2
Serial.write((byte)0x0); >>> 0x00
Serial.write((byte)0x0); >>> 0x40
Serial.write((byte)0x0); >>> 0xB8
Serial.write(0xFF); >>> 0xF4
Serial.write(0xFF); >>> 0x1F
https://imgur.com/a/fiP6lF6

After uploading the code, the digital pin is not toggling anymore. Is there wrong I am doing by adressing the Xbee device through its serial number?
asked Feb 11 in IEEE 802.15.4 by zazas321 New to the Community (2 points)

Please log in or register to answer this question.

2 Answers

0 votes
If you're changing the value in the address field, then the checksum will also change, so you need to dynamically calculate your checksum

this line:
//checksum
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '4' + value;
Serial.write(0xFF - (sum & 0xFF));
answered Feb 13 by DystopianFerret Veteran of the Digi Community (365 points)
0 votes
It worked! Thanks a lot. What a silly mistake - i forgot to change the checksum after I have changed the address
answered Feb 19 by zazas321 New to the Community (2 points)
...