hi, i am using xbee series 2 and my project objective is using 1 arduino uno board to communicate with 1st xbee and then to the 2nd xbee. and this 2nd xbee is to control a buzzer. the buzzer will trigger based on the RSSI value. because i am using in API mode which 1 xbee is end device(receiver) in AT mode and another xbee is coordinator(sender) in API mode, i have problems that unable to allow both xbees to communicate and the RSSI value is not shown on the serial monitor. the xbees are configured properly and i am not confident in my code as well. much help will be appreciated! here is my code :
const int ledpin = 13; // ledpin location
int inByte; // val
const int rssiPin = 9; // rssipin 1 location
const int rssiPin1 = 10; // rsssipin 2 locationunsigned long rssi1;
unsigned long rssi2;void setup() {
Serial.begin(9600);
pinMode(ledpin, OUTPUT)l; // declare ledpin
pinMode(rssiPin,INPUT); // declare rssiPin
pinMode(rssiPin1,INPUT);
}void loop () {
rssi1= pulseIn(rssiPin, HIGH,200); //Reads a pulse(HIGH) on a pin
Serial.print("RSSI 1 value is ");
Serial.print(rssi1); // display at serial monitor
Serial.print ('\t');
Serial.println('H'); // sends a 'H' to on the ledpin at D1 of xbee(receiver)
delay(500);rssi2 = pulseIn(rssiPin1, LOW, 200); //Reads a pulse(LOW) on a pin
Serial.print("RSSI 1 value is ");
Serial.print(rssi2);
Serial.print ('\t');
Serial.println('L'); // sends a 'L' to on the ledpin at D1 of xbee
delay(500);if (Serial.available() > 0) { // if we have received at least one frome worth of bytes
inByte = Serial.read(); // read in a byte
Serial.print(inByte);if (inByte == 'H') {
digitalWrite(ledpin, HIGH);
remotestate(0x05); // turn on led
}
else if (inByte == 'L') {
digitalWrite(ledpin, LOW);
remotestate(0x04); // turn off led
}
}
}// API frame protocol
void remotestate(int value) { // pass either a 0x4 or and 0x5 to turn the pin on or off
Serial.write((byte)0x7E); // start byte
Serial.write((byte)0x0); // high part of length (always zero)
Serial.write((byte)0x10); // low part of length (the number of bytes that follow, not including checksum)
Serial.write((byte)0x17); // 0x17 is a 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)00);
Serial.write((byte)0x13); //destination HIGH address
Serial.write((byte)0xA2); //destination HIGH address
Serial.write((byte)00); //destination HIGH address
Serial.write((byte)0x40); //destination LOW address
Serial.write((byte)0x91); //destination LOW address
Serial.write((byte)0xA2); //destination LOW address
Serial.write((byte)0x89); //destination LOW address
// 16 bit of recipient or 0xFFFE if unknown
Serial.write((byte)0xFB); //16-bit address
Serial.write((byte)0x28); //16-bit
Serial.write((byte)0x02); // 0x02 to apply changes immediately on remote
// command name in ASCII characters
Serial.write((byte)'D'); //set Pin number D1 'D' = 0x44
Serial.write((byte)'0'); //'0' = 0x30
// command data in as many bytes as needed
Serial.write((byte)value);
// checksum is all bytes after length bytes
long sum = 0x17 + 0x13 + 0xA2 + 0x40 + 0x91 + 0xA2 + 0x89 + 0xFB + 0x28 + 0x02 + 'D' + '0' + value;
Serial.write((byte)( 0xFF - ( sum & 0xFF)) ); // calculate the proper checksum
//delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
delay(500);
}