Go Down

Topic: About setting up communication between XBee Pro (Read 2329 times) previous topic - next topic

garychow1411

Hi all,
   In a recent project, I want to capture the acceleration data from an acceleromter and send to my PC through a pair of Xbee Pro tranceivers.  I had got all the components ready, but i need to prepare a program for the devices.  
   I am very new in this field...however, I still need to make this prototype for my project...
  Could anyone give me advice how could i get started to program???? Is there any simple program code existed which i can make good use of?

   Here's my component:
   Sensor board:
   1 Arduino Main Board
sku: DEV-00666
   1 XBee Shield
sku: WRL-09588
   1 Triple Axis Accelerometer Breakout - ADXL345
sku: SEN-09156
 

   Receiver Board:
   1  XBee Pro 60mW Wire Antenna
sku: WRL-08742
   1  XBee Explorer USB
sku: WRL-08687


Thank you very much. I really need your help..

PaulS

What kind of XBees do you have (series 1 or 2/2.5)?

How have you configured them?

Have you tested that they can communicate?

What code do you have running on the Arduino to capture the accelerometer data?

When is your homework due?
The art of getting good answers lies in asking good questions.

garychow1411

hi PaulS,
 I am using this Xbees http://www.sparkfun.com/commerce/product_info.php?products_id=8742.
 
 I have currently connected the sensor and the Arduino according to the setup in this website. http://codeyoung.blogspot.com/2009/11/adxl345-accelerometer-breakout-board.html
 Now the sensor can send data through USB cable to my PC.
 But how can i change my code to send the data through my pair of transceivers???
 This is the code i am using now:
Code:

#include <Wire.h>

#define DEVICE (0x53)    //ADXL345 device address
#define TO_READ (6)        //num of bytes we are going to read each time (two bytes for each axis)

byte buff[TO_READ] ;    //6 bytes buffer for saving data read from the device
char str[512];                      //string buffer to transform data before sending it to the serial port

void setup()
{
 Wire.begin();        // join i2c bus (address optional for master)
 Serial.begin(9600);  // start serial for output
 
 //Turning on the ADXL345
 writeTo(DEVICE, 0x2D, 0);      
 writeTo(DEVICE, 0x2D, 16);
 writeTo(DEVICE, 0x2D, 8);
}

void loop()
{
 int regAddress = 0x32;    //first axis-acceleration-data register on the ADXL345
 int x, y, z;
 
 readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
 
  //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
  //thus we are converting both bytes in to one int
 x = (((int)buff[1]) << 8) | buff[0];  
 y = (((int)buff[3])<< 8) | buff[2];
 z = (((int)buff[5]) << 8) | buff[4];
 
 //we send the x y z values as a string to the serial port
 sprintf(str, "%d %d %d", x, y, z);  
 Serial.print(str);
 Serial.print(10, BYTE);
 
 //It appears that delay is needed in order not to clog the port
 delay(15);
}

//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.send(address);        // send register address
  Wire.send(val);        // send value to write
  Wire.endTransmission(); //end transmission
}

//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[]) {
 Wire.beginTransmission(device); //start transmission to device
 Wire.send(address);        //sends address to read from
 Wire.endTransmission(); //end transmission
 
 Wire.beginTransmission(device); //start transmission to device
 Wire.requestFrom(device, num);    // request 6 bytes from device
 
 int i = 0;
 while(Wire.available())    //device may send less than requested (abnormal)
 {
   buff = Wire.receive(); // receive a byte
   i++;
 }
 Wire.endTransmission(); //end transmission
}


PaulS

How are you connecting the XBee to the Arduino? Are you using a shield? If so, which one?
The art of getting good answers lies in asking good questions.

garychow1411

I'm using this one
 1 XBee Shield
sku: WRL-09588
http://www.sparkfun.com/commerce/product_info.php?products_id=9588

PaulS

Quote
Now the sensor can send data through USB cable to my PC.
But how can i change my code to send the data through my pair of transceivers???


No changes to the code are required.

The switch on the shield needs to be in the correct position. It needs to be in one position for the PC to talk to the Arduino, and in the other position for the Arduino to talk to the XBee.
The art of getting good answers lies in asking good questions.

garychow1411

THanks PaulS,

   If now I'm using a XBee Explorer to connect the PC and receiving data from the arduino-accelerometer board through wireless, what setting or code should i use?

Go Up