Xbee RSSI signal strenght reader

Hello Arduina, hel

Hello Arduina, and hello everybody! :) I'm quite new with Arduino and I'm now facing the same problem that was posted in this forum.. I've tried to wire the XBee board pin 6 (I'm using this XBee Simple Board http://www.robot-italy.com/product_info.php?products_id=749) to the analog pin 3 on the Arduino. I've used this code, but it's not working and I don't know why.. :'(

/*
   XBee_Receive_Example3_modifiedRSSI
  
  An example of using the Arduino board to receive data from the 
  computer.  In this case, the Arduino boards turns on an LED when
  it receives the character 'H', and turns off the LED when it
  receives the character 'L'.
  
  The data can be sent from the Arduino serial monitor, or another
  program like Processing (see code below), Flash (via a serial-net
  proxy), PD, or Max/MSP.
  
  The circuit:
  * LED connected from digital pin 13 to ground
  
  created 2006
  by David A. Mellis
  modified 14 Apr 2009
  by Tom Igoe and Scott Fitzgerald
  
  modified 2009
  by Marta86
  
  http://www.arduino.cc/en/Tutorial/PhysicalPixel
  */

 const int ledPin = 13; // the pin that the LED is attached to
 int incomingByte;      // a variable to read incoming serial data into
#define analogPin 3
 int RSSI=0; // holds the Received Signal Strength Value
int address=0; // holds the 16-bit address of the sender

 void setup() {
   // initialize serial communication:
   Serial.begin(9600);
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);
     pinMode(analogPin, INPUT);
    

 }

 void loop() {
   // see if there's incoming serial data:
   if (Serial.available() > 0) {
     // read the oldest byte in the serial buffer:
     incomingByte = Serial.read();
     // 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:
     if (incomingByte == 'L') {
       digitalWrite(ledPin, LOW);
     }
   }
   address = Serial.read(); // the sixth byte is the low part of the address
      RSSI = Serial.read(); // the seventh byte is the RSSI value
      analogWrite(10,(100-RSSI)*2); // analog write a brightness roughly corresponding to distance
 }

..Could please someone help me? Arduina, could you maybe post your code? (ehm.. and if u are italian, we can write in italian too, would be easier for me ;) ..)

Tx a lot 8-)

Hello everybody, i’ve tried to upload the following sketch on the first Arduino + XBee (the “sender unit”):

/*
   XBee_Send_Example3_modifiedRSSI
  
  An example of using the Arduino board to send data from the 
  computer.  In this case, the Arduino boards should send the RSSI value to the other XBee
  
  The data can be sent from the Arduino serial monitor, or another
  program like Processing (see code below), Flash (via a serial-net
  proxy), PD, or Max/MSP.
  
  created 2006
  by David A. Mellis
  modified 14 Apr 2009
  by Tom Igoe and Scott Fitzgerald
  
  modified 2009
  by Marta86
  
  http://www.arduino.cc/en/Tutorial/PhysicalPixel
  */
  
  int RSSI=0; // holds the Received Signal Strength Value

 void setup()
{
  Serial.begin(9600);
}

void loop()
{
  RSSI = Serial.read();
  Serial.print(RSSI);
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

Then, i’ve uploaded this sketch to the second Arduino+XBee (the receiving unit):

/*
   XBee_Receive_Example3_modifiedRSSI
  
  An example of using the Arduino board to receive data from the 
  computer.  In this case, the Arduino boards turns on an LED when
  it receives the character 'H', and turns off the LED when it
  receives the character 'L'.
  
  The data can be sent from the Arduino serial monitor, or another
  program like Processing (see code below), Flash (via a serial-net
  proxy), PD, or Max/MSP.
  
  The circuit:
  * LED connected from digital pin 13 to ground
  
  created 2006
  by David A. Mellis
  modified 14 Apr 2009
  by Tom Igoe and Scott Fitzgerald
  
  modified 2009
  by Marta86
  
  http://www.arduino.cc/en/Tutorial/PhysicalPixel
  */

 const int ledPin = 13; // the pin that the LED is attached to
 int incomingByte;      // a variable to read incoming serial data into
#define analogPin 3
 int RSSI=0; // holds the Received Signal Strength Value
int address=0; // holds the 16-bit address of the sender

 void setup() {
   // initialize serial communication:
   Serial.begin(9600);
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);
    

 }

 void loop() {
    //address = Serial.read(); // the sixth byte is the low part of the address
      //RSSI = Serial.read(); // the seventh byte is the RSSI value
   // see if there's incoming serial data:
   if (Serial.available() > 0) {
     // read the oldest byte in the serial buffer:
     incomingByte = Serial.read();
     
     // if it's the RSSI value (ASCII 72), print the value on the serial:
     if (Serial.read() == RSSI) {
       Serial.print("RSSI");
     }
     
     // if it's a capital H (ASCII 72), turn on the LED:
     if (incomingByte == 'H') {
       digitalWrite(ledPin, HIGH);
       Serial.print("HIGH");
     } 
     // if it's an L (ASCII 76) turn off the LED:
     if (incomingByte == 'L') {
       digitalWrite(ledPin, LOW);
       Serial.print("LOW");
     }
   }
  
      //Serial.print(10,(100-RSSI)*2); // analog write a brightness roughly corresponding to distance
 }

In this way I can see a series of <<-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL-1HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL87HL72HL73HL71HL72HL76HL79HL>>
on the serial monitor… a certain value, “H” that means HIGH and “L” that means LOW. On the first and second time, the value was -1 when the receiving unit was disconnected, and was turning into 76, 79, 87, or whathever, once connected… from the third time I’ve tried to disconnect the receiver, the sender unit simply continued to return 76, 79 or whathever continuously, like nothing was happened…
On the receiving unit, I simply have my LED turning on and off depending on the char received, and LOWHIGHLOWHIGH… is written on the serial monitor… but not the RSSI value! :frowning:

Could anyone help me? I need to have the RSSI value in order to finish my project!! :’(

Thnks a lot!

Marta

In the sender, you perform a Serial.read to get a value. I have no idea what value you are reading, or where it came from.

Then, you print whatever you read, followed by an H, and, after a 1 second delay, an L.

On the receiver, you are reading the values sent, and checking if the first value is RSSI, which you have defined to be 0.

Presumably, then, the RSSI value is never printed, because the value is never 0. The comment in the receiver code about RSSI is meaningless to the compiler, and does not describe the RSSI variable as you have defined it.

So… what do you suggest I should write instead of RSSI=0 ?
I mean, how can I say to the sending unit to get exactly the RSSI value, and not another one that I don’t know where it comes from?

I would like to write something like this:
In the sender unit code:
RSSI = read the distance between me and the receiver;
if (RSSI<a certain value) {
say to the receiver to do something -switch on a LED or whathever-
}

In the receiving unit code:
read the RSSI value sent from the sender, so do what sender says

The sender should send something like this:

78,H

where '>' is the start of valid data, 78 is the RSSI value, and H (or L) is how to set the LED.

The receiver should look for the > as the start of a sequence of values, should read up to the comma as the RSSI value, converting each character to an integer (by subtracting '0'), multiplying the old value by 10, and adding the new value, and then reading the LED state.