Go Down

Topic: Read Xbee Pro RSSI - what is wrong? (Read 620 times) previous topic - next topic

charlotte1988

Hello All!

I have worked for some days now how to read the RSSI from one Xbee Pro. I'm quite new at this so any help will be appreciated.

I have a setup as follow: 1 explorer regualeted(breakout board), 1 Mega 2650 and 1 Xbee Pro talking to another set of 1 explorer regualeted, 1 Mega 2650 and 1 Xbee Pro. I have soldered a wire from pin 6 on the explorer regulated(Xbee) to analog input A0 on the arduino Mega board, because I'm trying to read the RSSI-value this way.

I have no problem getting the two radios communicating, but I can't read the right value of RSSI on the receiver. I get a signal, but it does not varies more than two or three values, so when I print out the signal from the analog in pin I get 698...697...698..ect. even if I move the transmitter 10 meters away it does not change value. 

Anybody who knows what I miss?
 
My code is:

Transmitter has code as follows:
Code: [Select]

const int ledPin = 13;

void setup() {

// initialiserer seriel kommunikation
Serial.begin(9600);
Serial.println("Welcome!");
// initialiserer seriel kommunikation
Serial1.begin(9600);
// initialiserer led output
pinMode(ledPin, OUTPUT);

//sætter destinationsadresse
setDestination();
//start program
blink(ledPin,3);

}

void setDestination(){
 
  //radio i kommand-mode
  Serial1.print("+++");
  //vent til at radioen svarer med "ok\r"
  char thisByte = 0;
  while (thisByte != '\r'){
    if (Serial1.available() > 0){
      thisByte = Serial1.read();
      Serial.println(thisByte);
    }
  } 
  // sæt destinationsadresen. Her bruges 16-bit adressering.
  // Her bruges to radioer. Den ene radios destiantion skal
  // være den anden radios MY adresse - og omvendt.

Serial1.print("ATDH0, DL5678\r");
// sætter min MY
Serial1.print("ATMY1234\r");
// Sæt Personal Area Network ID
Serial1.print("ATID1111\r");
// sæt radio til data mode
Serial1.print("ATCN\r");
}
 
void blink (int thisPin, int howManyTimes){
for (int blinks =0; blinks< howManyTimes; blinks++){
  digitalWrite(thisPin, HIGH  );
  delay(200);
  digitalWrite(thisPin,LOW);
  delay(200);
}
}

void loop(){
 
  Serial1.print('H');
  delay(1000);
  Serial1.print('L');
  delay(1000); 
  }
   

Reciever has code as follows:
Code: [Select]


const int ledPin = 13;
int sensorPin =A0;
int incomingByte;

void setup() {

// initialiserer seriel kommunikation
Serial.begin(57600);
Serial.println("Welcome!");
// initialiserer seriel kommunikation
Serial1.begin(9600);
// initialiserer led output
pinMode(ledPin, OUTPUT);
//pinMode(sensorPin, INPUT);

//sætter destinationsadresse
setDestination();
//start program
blink(ledPin,3);

}

void setDestination(){ 
  //radio i kommand-mode
  Serial1.print("+++");
 
  //vent til at radioen svarer med "ok\r"
  char thisByte = 0;
  while (thisByte != '\r'){
    if (Serial1.available() > 0){
      thisByte = Serial1.read();
     // Serial.print(thisByte);
    }
  } 
  // sæt destinationsadresen. Her bruges 16-bit adressering.
  // Her bruges to radioer. Den ene radios destiantion skal
  // være den anden radios MY adresse - og omvendt.

Serial1.print("ATDH0, DL1234\r");
// sætter min MY
Serial1.print("ATMY5678\r");
// Sæt Personal Area Network ID
Serial1.print("ATID1111\r");

// sæt radio til data mode
Serial1.print("ATCN\r");

}
void blink (int thisPin, int howManyTimes){
for (int blinks =0; blinks< howManyTimes; blinks++){
  digitalWrite(thisPin, HIGH  );
  delay(200);
  digitalWrite(thisPin,LOW);
  delay(200);
}
}

void loop(){
  if (Serial1.available() > 0) {
    while (Serial1.available() > 0) {
      // read the oldest byte in the serial buffer:
      incomingByte = Serial1.read();
      // Serial.println("value: " + incomingByte);
      // if it's a capital H (ASCII 72), turn on the LED:
      if (incomingByte == 'H') {
        digitalWrite(ledPin, HIGH);
      }
      // if it's an L (ASCII 76) turn off the LED:
      else if (incomingByte == 'L') {
        digitalWrite(ledPin, LOW);
      }
       }

int var;
var = analogRead(sensorPin);
Serial.println(var);

//Serial.println(var);
//delay(2000);

}
}


All help will be much appreciated!!

Kind regards

Charlotte


Go Up