Good day to you!
I am doing a project to track an object using Arduino-XBee S2 pairs and I am trying to retrieve the RSSI value. I have found a code to get the RSSI value using AT commands as below. One XBee S2 have been set as Coordinator AT and the other have been set as Router AT. I am using one Arduino Uno and one Arduino Nano. Here is the code for the transmitter and receiver:
Transmitter:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.println("I am Porky, ");
}
int second;
int minute = 0;
int hour = 0;
void loop()
{
for (int second=0; second<=59; second++) // count 60 seconds
{
Serial.println("\n I am Porky, ");
lcd.setCursor(0, 1);
lcd.print(hour);
Serial.print(hour);
lcd.print(":");
Serial.print(":");
lcd.print(minute);
Serial.print(minute);
lcd.print(":");
Serial.print(":");
lcd.print(second);
Serial.print(second);
second++;
second++;
second++;
second++;
delay(4999);
}
second = 0; // 60 seconds later reset to zero
minute ++; // add 1 minute
if (minute>=59) // if 60 minutes has passed
{
minute=0; // reset minutes to zero
hour++; // increment one hour
}
if (hour>=24) // if 24 hours has passed
{
hour=0; // reset to zero hour and start over
}
}
Receiver:
char incomingByte; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
delay(4000);
Serial.print("Router x\n");
}
//When there is serial data it reads and sends whatever is received. No data, only router x will be transmitted.
void serialEvent(){
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
}
delay(2000);
Serial.print("+++");
delay(1000);
Serial.print("\n");
Serial.println("ATDB");
delay(100);
while (Serial.available() > 0) {
Serial.write(Serial.read());
Serial.setTimeout(2000);
}
Serial.println();
Serial.println("\n");
Serial.println("ATCN");
delay(100);
while (Serial.available() > 0) {
Serial.write(Serial.read());
Serial.setTimeout(2000);
}
Serial.println();
Serial.flush();
}
When I sketched these two codes, I could not get the RSSI value on the serial monitor as supposed. I am thinking of the mistake about the serial connection as I do not have any Arduino-XBee shield. I only connected them by wiring. Could you please help me clarify this. Much appreciated.
![WP_20131211_18_48_00_Pro[1].jpg](https://europe1.discourse-cdn.com/arduino/original/3X/1/9/19a8c1c8ca0d52fdeb3775537d6c8a0aae9a1fe1.jpg)