wireless alarm laptop

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 location

unsigned 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);
}

So, you are trying to use THE serial port to talk to the PC AND to the XBee. You don't think that will confuse the XBee?

How is the XBee connected to the Arduino?

You need to have both XBees in API mode or both in AT mode. One in API mode and one in AT mode won't work.

hi PaulS,

PaulS:
So, you are trying to use THE serial port to talk to the PC AND to the XBee. You don't think that will confuse the XBee?

yea, i need to talk to the xbee and PC to show the results (RSSI value) first then afterthat i proceed on with measuring the PWM signal which then the PC is not required anymore.

PaulS:
How is the XBee connected to the Arduino?

the coordinator(sender) is connect with arduino uno
Din > TX
Dout > RX
GND > GND
3.3V > 3.3V

the end device(receiver) is connect to the buzzer
D1 > buzzer
GND and 3.3V is connected to the another arduino to provide power supply.

the coordinator(sender) is connect with arduino uno
Din > TX
Dout > RX
GND > GND
3.3V > 3.3V

the end device(receiver) is connect to the buzzer
D1 > buzzer
GND and 3.3V is connected to the another arduino to provide power supply.

So, nothing on either XBee is connected to pins 9 or 10 of the Arduinos. And, yet, you think that somehow you will magically get RSSI values reading from unconnected pins. Want to buy a bridge?

oh! sorry! i forgot to mention that the pin 6 of xbee(transmitter side) is connected to pin 9. so sorry about it! =(

"AT mode and another xbee is coordinator(sender) in API mode"

This absolutely WILL NOT work. To use AT mode (think of it as a wireless serial port) both Xbee modules need to be configured in AT mode with each other's address. They act as a very simple wireless link.

To use API mode, one must be a coordinator and the other a router or endpoint. They need to have the same network ID and be configured properly. I would suggest you start with simply configuring both Xbees to be in API mode (one as coordinator, one as router) and testing connectivity by sending a remote AT command (such as ATPL for reading the Power Level, return value is 0-4) with a non-zero Frame ID such that you get a response frame back. After you can successfully communicate in API mode than you can start to debug the rest.

BTW in your code "Serial.write((byte)value);" where is "value" declared and set?

I've never tried to share the serial port with the XBee so I don't know if that would cause issues. Presumably as long as you don't print a "~" which is the packet start delimiter then I guess the XBee module discards the bytes but I don't know that for sure. If you have a Mega lying around connect the XBee to the second serial port.

hi ybl84f1, thanks for the comment. i have tried using both xbee on API mode.( 1 end device, the other coordinator) and also i enable both API 2 mode. but still is not communicating in the terminal tab =(. the configuration is at the attachment, i am not sure what have i done wrong. =( i am using xctu to do these settings btw.

2 xbee comfiguration.docx (217 KB)