how to read multiple data using xbee as a medium of transmission

im currently using xbee to transfer data from one xbee to another. i have a total of 5 different data to be transfered to the another xbee. how can i read this data in another xbee

There are nowhere near enough details in your post. Are the XBees connected to Arduinos? If so, how? What kind of XBees are they? How are they configured?

the xbees are connected to the arduino rx-rx and tx-tx
xbee s1 is the type of xbee and they are configured using the x-ctu

by the way this the essential part of my code

on the sending part

const byte spiclk=17; // connect to ADXL CLK
const byte spimiso=16; // connect to ADXL DO
const byte spimosi=15; // connect to ADXL DI
const byte spics=14; // connect to ADXL CS

byte xyz[8]; // raw data storage
int x,y,z; // x, y, z accelerometer data
double fXg = 0; // x, y, z accelerometer data in degrees
double fYg = 0;
double fZg = 0;
const float alpha = 0.5;
byte spiread;

void setup(void){
Serial.begin(9600); // serial i/o for test output
init_adxl(); // initialize ADXL345


void loop(void){

read_xyz(); // read ADXL345 accelerometer

// and then send results to serial port
// view results by using IDE Tools>Serial Monitor

Serial.print("x = “);
Serial.print(” y = “);
Serial.print(” z = ");


double pitch, roll;

//Low Pass Filter
fXg = x * alpha + (fXg * (1.0 - alpha));
fYg = y * alpha + (fYg * (1.0 - alpha));
fZg = z * alpha + (fZg * (1.0 - alpha));

//Roll & Pitch Equations
roll = (atan2(-fYg, fZg)180.0)/M_PI;
pitch = (atan2(fXg, sqrt(fYg
fYg + fZg*fZg))*180.0)/M_PI;

Serial.print(" pitch = “);
Serial.print(" roll = “);
Serial.print(” ");

while (pitch && roll == 0 ){
if (pitch>45 && roll<45 && roll>-45){Serial.print(" moving north "); }

if (pitch<-45 && roll<45 && roll>-45){Serial.print(" moving south ");}

if (pitch<45 && pitch>-45 && roll>45 ){Serial.print(" moving east ");}

if (pitch<45 && pitch>-45 && roll<-45 ){Serial.print(" moving west ");}

if ( pitch<45 && pitch>-45 && roll<45 && roll>-45 ){Serial.print(" IDLE STATE ");}


void spi_out(byte spidat){
byte bitnum=8;

// start spi bit bang

pinMode(spiclk,OUTPUT); // SPI CLK =0
if((spidat & 0x80)!=0)
pinMode(spimosi,INPUT); // MOSI = 1 if MSB =1
pinMode(spimosi,OUTPUT); // else MOSI = 0

pinMode(spiclk,INPUT); // SPI CLK = 1

// read spi data

if(digitalRead(spimiso)==HIGH) spiread |= 0x01; // shift in a 1 if MISO is 1

pinMode(spimosi,INPUT); // reset MOSI to 1


/* Initialize ADXL345 */

void init_adxl(void){
pinMode(spics,OUTPUT); // CS=0
//Write to register 0x31, DATA FORMAT
// uncomment your desired range
spi_out(0x0B); //full resolution, +/- 16g range
//spi_out(0x0A); //full resolution, +/- 8g range
//spi_out(0x09); //full resolution, +/- 4g range
// spi_out(0x08); //full resolution, +/- 2g range

pinMode(spics,INPUT); //CS HIGH
pinMode(spics,OUTPUT); // CS=0

// Write to register 0x2d, POWER_CTL
//set to measure mode
pinMode(spics,INPUT); //CS HIGH


Read all 3 axis x,y,z

void read_xyz(void){
int i;
pinMode(spics,OUTPUT); // CS=0
//Set start address to 0x32
//D7= 1 for read and D6=1 for sequential read
// dump xyz content to array

  • }*

  • // merge to convert to 16 bits*

  • x=((int)xyz[1]<<8) + xyz[0];*

  • y=((int)xyz[3]<<8) + xyz[2];*

  • z=((int)xyz[5]<<8) + xyz[4];*

  • pinMode(spics,INPUT); //CS HIGH*
    and this is code for the receiving part
    int pitch=0;
    int roll=0;
    int pitch2,roll2;
    void setup() {
    void loop() {

  • if (Serial.available()>0){Serial.write(;pitch2=pitch;}*

  • while (pitch && roll == 0){if (pitch>45 && roll<45 && roll>-45){Serial.print(" moving north2 "); }*

  • if (pitch<-45 && roll<45 && roll>-45){Serial.print(" moving south2 ");}*

  • if (pitch<45 && pitch>-45 && roll>45 ){Serial.print(" moving east2 ");}*

  • if (pitch<45 && pitch>-45 && roll<-45 ){Serial.print(" moving west2 ");}*

  • if ( pitch<45 && pitch>-45 && roll<45 && roll>-45 ){Serial.print(" IDLE STATE2 ");}*

pitch2=pitch; // i have put this so that i can check whether the xbee can understand the data receive individually

  • Serial.print(pitch2);*

  • roll2=roll;*

  • Serial.print(roll2);*

  • delay(250);}*

  • }*

how can i get the multiple data transmitted by the sender and make the receiver part understand it individually. Thank you for your time reading this post :smiley:

I really don’t think that shifting data by 8) positions is going to prove useful. There are sticky posts at the top of the forum. You need to read them.

  if (Serial.available()>0){Serial.write(;pitch2=pitch;}

Too stupid for words. ONE STATEMENT PER LINE.

  if (Serial.available()>0)

Now, explain this. If there is serial data to read, read and print it, but don’t actually use it.

Why bother sending it?

while (pitch && roll == 0){if (pitch>45 && roll<45 && roll>-45){Serial.print("       moving north2      "); }

If pitch is not 0, and roll is, enter an infinite loop. How useful. Perhaps NOW you can see why ONE STATEMENT PER LINE, and proper placement of { is SO important.

Are you using the Serial port to talk to the XBee OR to talk to the PC? Both is the wrong answer. So is yes.

actually im currently testing it first in the PC first so that i can see the results first if it can read the data incoming.

If it pass i shall place the replace the

if (pitch>45 && roll<45 && roll>-45){
Serial.print(" moving north2 ");

and others with

if (pitch>45 && roll<45 && roll>-45){

void Driveforward(){

digitalWrite(RightMotorForward, HIGH);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(LeftMotorReverse, LOW);

what im currently confused right now is that how can i read the multiple variables being sent by the transmitter and put them into their right position in which there will be no overlap of data with one another.

roll<45 && roll>-45

How is >-45 interpreted? Is -50, or -40, greater than -45?
Just wondering.

Forget about how you intend to use the data. Write a sketch that simply reads the data from the XBee (using a SoftwareSerial instance and two pins other than 0 and 1) and prints it using the Serial.print() method.

Open the Serial Monitor application, and show us the data that you get.

When you know what the data looks like, you can write code to save the data for parsing.

When that works, you can write the code to parse the data.

When that works, you can put your infinite loops back in place.

this is the data i get in the serial monitor using the codes i have use

in this i cant see the

(" moving north2 ") and others

which will make me did not understand whether the xbee can understand the pitch =(pitch data transmit) or it just understand that it is the just 2nd data transmit


i think something like this

roll is between -45 and 45

if my memory serves it right the arduino did not take my


or i just happen not to do it right so i put it like this

roll<45 && roll>-45

When you decide to ditch that crappy code, and do what I suggested, I'll pay attention again.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only

// set the data rate for the SoftwareSerial port


void loop() // run over and over
Serial.println(“Goodnight moon!”);
mySerial.println(“Hello, world?”);
if (mySerial.available())
if (Serial.available())

only the

(“Goodnight moon!”)

return to the serial monitor but the

(“Hello, world?”)

did not, can i ask why it did not return?

i have connected the rx-tx to the pins 10 and 11 and that is the result
i have also tried if rx-tx is connected to the rx-tx(pin 0 and 1) but it still displays the same result

can you please enlightened me.

can i ask why it did not return?

Return from where? You sent that data to pins 10 and 11. You may, or may not, have something connected to those pins. That device may, or may not, read the data. That device may, or may not return something.

i have connected the rx-tx to the pins 10 and 11 and that is the result

The RX and TX pins of what?

i have also tried if rx-tx is connected to the rx-tx(pin 0 and 1) but it still displays the same result

The RX and TX pins of what?

while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only

Do you have a Leonardo? If not, why is this code here?

How are they configured?

they are configured using the x-ctu

What we have here is a failure to communicate.

What did you set MY and DL to on the first XBee? What did you set MY and DL to on the second XBee?

Are the PAN ID settings the same on both XBees?