Quantcast
Channel: Arduino Hacks » Arduino projects
Viewing all articles
Browse latest Browse all 10

Getting Xbee RSSI value Using Arduino

$
0
0

RSSI stands for received signal strength indication. It is the measure of the power that is present in an incoming radio signal. Getting xBee RSSI value using Arduino is possible and sometimes comes in handy in xBee projects. I previously worked on a project that required me to get the RSSI value of received data in my xBee and had a really hard time doing that. This is because there isn’t much on this topic online. So I decided to write a small tutorial on it.

Hardware Requirement

  • 2 xBee modules
  • 1 xBee shield
  • xBee explorer or adapter
  • Arduino uno
  • 16×2 LCD screen (optional)
  • Potentiometer (optional)

xbee-arduino uno-lcd-explorer

 

Connection

Before connecting anything, configure the two xBee modules to API = 2 mode. See how to do that here. Once you have done that, you can proceed with the rest of the connection.

Mount one of the xbee modules onto the xBee explorer or adapter and connect it to the computer.

xbee explorer

Mount the other xBee onto the xBee shield and then onto the Arduino uno. Ensure the 3.3v jumpers are not on and move the DI and DO jumpers to D9 and D8 respectively as shown in this tutorial. I will explain later why we move the DI and DO jumpers to D9 and D8 respectively.

xbee mounted on shield

Connect the LCD screen onto your setup as shown in this link

xbee RSSI setup

I used an LCD on my setup, because I wanted to display the RSSI value on the LCD screen. You don’t have to do that. You can decide to display the RSSI values on the serial monitor.

Libraries

The libraries I used include:

  • liquidCyrstal library (already in the IDE)
  • softwareSerial library (already in the IDE)
  • xBee library

Code

Upload the code below in on your Arduino

#include <XBee.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

// XBee's DOUT (TX) is connected to pin 8 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 9 (Arduino's Software TX)
SoftwareSerial serial1(8, 9); // RX, TX

XBee xbee=XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();

uint8_t option = 0;
uint8_t data = 0;
uint8_t rssi = 0;

void setup() 
{
  Serial.begin(9600);
  serial1.begin(9600);
  xbee.setSerial(serial1);
  lcd.begin(16,2);
  lcd.clear();
}

void loop() 
{
  xbee.readPacket(100);
  if (xbee.getResponse().isAvailable())
  {
    Serial.println("available");
    if(xbee.getResponse().getApiId() == RX_64_RESPONSE || xbee.getResponse().getApiId() == RX_16_RESPONSE)
    { 
      Serial.println("16");
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE) 
      {
        Serial.println("16");
        xbee.getResponse().getRx16Response(rx16);
        rssi = rx16.getRssi();
        lcd.clear();
        lcd.print(rssi);
        Serial.println(rssi);
      } 
      else 
      {
        Serial.println("64");
        xbee.getResponse().getRx64Response(rx64);
        rssi = rx64.getRssi();
        lcd.clear();
        lcd.print(rssi);
        Serial.println(rssi);
      }
    }
  }
}

 

Once you have uploaded the code onto your Arduino board, open XCTU and connect the xBee that is mounted on the explorer/adapter. You can see how to do that here. Create a data frame and the send it in an infinite loop that has an interval of 100ms. Click here to see how to do it

Operation

The xBee that is connected to the computer will be sending data packets to the xBee that is mounted onto the Arduino. Each data packet contains an RSSI value. This makes getting the xBee RSSI value easier. The code on the Arduino sifts out the rest of the information on the data packet and gets the RSSI value. The RSSI value is then displayed on the serial monitor and on the LCD screen. To see the project in action, play the video below.

Video

Related Links

The post Getting Xbee RSSI value Using Arduino appeared first on Arduino Hacks.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images