Pages: [1]   Go Down
Author Topic: Arduino + xbee + api  (Read 614 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the setup

2 x arduino
2 x xbee series 1 + usb board

my actual project involves atleast 5-6 of the above

and this is what i got to do

1. broadcast a msg to all the xbees
2. record the signal strength for each packet so that i can get a rough measurement of distance of each module

now from what i've read the API packets have the rss values and can also transmit data... so i thought may be the data transmitted can be used to identify the individual module by manually setting it.

the problem:

im not even able to get two boards communicating in API mode... i've been at it for three days now, gone thru numerous tutorials...
have even installed the xbee.h library... still nothing works smiley-sad... and since im new to this whole thing, i think im missing something basic
which might be trivial to ppl that they havent mentioned newhere smiley-sad....

would help me a ton if someone could post the code for a simple api data transfer with the initial steps...



Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
record the signal strength for each packet so that i can get a rough measurement of distance of each module
There is no good correlation between signal strength and distance. Signal strength is a function of too many variables - battery voltage and current of the sender, distance, material that the signal passed through, interference, etc.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i jus need a rough measurement... something on the lines of close, far, too far....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well i used the xbee.h library's example tx program, and i only get an error smiley-sad

initial setup

connected an xbee to my laptop

ATMY FFFF
ATAP 2

here is the code on my arduino

i jus changed the address in txrequest to FFFF
and the value to be transmitted to r (pin5)

Code:
#include <XBee.h>

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };

// with Series 1 you can use either 16-bit or 64-bit addressing

// 16-bit addressing: Enter address of remote XBee, typically the coordinator

Tx16Request tx = Tx16Request(0xFFFF, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();

int pin5 = 0;

int statusLed = 11;
int errorLed = 12;

void flashLed(int pin, int times, int wait) {
    
    for (int i = 0; i < times; i++) {
      digitalWrite(pin, HIGH);
      delay(wait);
      digitalWrite(pin, LOW);
      
      if (i + 1 < times) {
        delay(wait);
      }
    }
}

void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);
  
  xbee.begin(9600);
}

void loop() {
  
   // start transmitting after a startup delay.  Note: this will rollover to 0 eventually so not best way to handle
    if (millis() - start > 15000)
    {
      // break down 10-bit reading into two bytes and place in payload
      pin5 = 20;
      payload[0] = pin5 >> 8 & 0xff;
      payload[1] = pin5 & 0xff;
      
      xbee.send(tx);

      // flash TX indicator
      flashLed(statusLed, 1, 100);
    }
  
    // after sending a tx request, we expect a status response
    // wait up to 5 seconds for the status response

    if (xbee.readPacket(5000))
       {
        // got a response!

        // should be a znet tx status            
     if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE)
          {
       xbee.getResponse().getZBTxStatusResponse(txStatus);
    
       // get the delivery status, the fifth byte
           if (txStatus.getStatus() == SUCCESS)
             {
             // success.  time to celebrate
             flashLed(statusLed, 5, 50);
             } else
             {
             // the remote XBee did not receive our packet. is it powered on?
             flashLed(errorLed, 3, 500);
             }
        }      
    }
else
    {
      // local XBee did not provide a timely TX Status Response -- should not happen
      flashLed(errorLed, 2, 50);
    }
    
    delay(1000);
}

when i run the code, my arduino serial monitor displays garbage value, the same one over and over again-->  (~   yE-   ~   yE-    ~   yE-)

is the abve changes sufficient or is there something i missed out on???
« Last Edit: October 29, 2011, 08:43:44 am by sarah36 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
when i run the code, my arduino serial monitor displays garbage value, the same one over and over again-->  (~   yE-   ~   yE-    ~   yE-)
Where do you write anything to the Serial Monitor/serial port?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nowhere.... but still i get some values
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What kind of XBees are you using? I have the Pros and I had to set one up as a coordinator and the other as a router.

I also have a version of the XBee.h and XBee.cpp that uses NewSoftSerial so you can talk to the computer from your arduino board while communicating with the XBee, really helps to debug.

Matt
Logged

Pages: [1]   Go Up
Jump to: