element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum question on wireless using two Xbees
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 9 replies
  • Answers 2 answers
  • Subscribers 419 subscribers
  • Views 787 views
  • Users 0 members are here
Related

question on wireless using two Xbees

kjhart0133
kjhart0133 over 13 years ago

Hello all,

 

I am using two Xbee S2 modules to remotely sample analog data from a potentiometer.  Here is my configuration.

 

The local Xbee is mounted to an Xbee shield on an Arduino Uno.

 

image

The remote Xbee has a potentiometer feeding voltage (0 to 1.2V) to Analog Input Zero on the Xbee (pin 20.)  The USB cable is just for 5V power.

 

image

The code is listed below.  The problem is that many of the data frames (frame type 0x92) that I get back from the remote are corrupted or otherwise wrong.  I can use the checksum to drop the bogus frames on the floor, but they do make up about 50% of the frames I receive.  Are other frames being sent by the remote Xbee, i.e. status or error frames, or something else?  Is this normal?

 

The local XBee (coordinator) is programmed separately in API mode; the remote XBee is programmed separately in Transparent mode (AT commands.)  Since I do get occasional correct frames of data, I think the XBees are programmed correctly

 

When I do get a good frame, the data in it is correct as you can see in the first picture [Ref. 2, pg. 114].

 

Can anyone help me out with this?

 

Thanks,

 

Kevin H.

 

References:

 

1.  Building Wireless Sensor Networks: with ZigBee, XBee, Arduino, and Processing, Robert Faludi, O'Reilly Press, 2010.

2.  XBee/XBee-Pro ZB RF Modules, Data Sheet, Digi International, Inc, November 2010.

 

Here is my code:

 

/*

This sketch reads ADI0 from the remote Xbee using a local (coordinator)

Xbee.  The input to the remote ADI0 is a potentiometer set from 0 to 1.2V

 

 

Kevin Hartnett, April 2013

Based on sample code from Building Wireless Networks: with Zigbee, Xbee,

  Arduino, and Processing, Robert Faludi, O'Reilly Press, 2010.

 

 

*** CONFIGURATION ***

 

SENDER: (REMOTE SENSOR RADIO)

ATID3456 (PAN ID)

ATDH -> set to SH of partner radio

ATDL  -> set to SL of partner radio

ATJV1 -> rejoin with coordinator on startup

ATD02  pin 0 in analog in mode

ATIR64 sample rate 100 millisecs (hex 64)

 

* THE LOCAL RADIO _MUST_ BE IN API MODE *

 

RECEIVER: (LOCAL RADIO)

ATID3456 (PAN ID)

ATDH -> set to SH of partner radio

ATDL  -> set to SL of partner radio

 

*/

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(7,8,9,10,11,12);

 

int debugLED = 13;

int analogValue = 0;

byte dataArray[40];  //set aside 40 bytes for data from sending unit

int length;

int i;

byte chksum;

 

void setup() {

  pinMode(debugLED, OUTPUT);

  Serial.begin(9600);

  lcd.begin(20, 4);

  lcd.clear();

  lcd.setCursor(0, 0);

}

 

void loop() {

 

  // make sure everything we need is in the buffer

  if (Serial.available() >= 21) {

    // look for the start byte

    dataArray[0] = Serial.read();

   

    if (dataArray[0] == 0x7E) {

      //blink debug LED to indicate when data is received

      digitalWrite(debugLED, HIGH);

      delay(10);

      digitalWrite(debugLED, LOW);

      //get length

      dataArray[1] = Serial.read();  //read msb of length

      dataArray[2] = Serial.read();  //read lsb of length

      length = dataArray[1]*256 + dataArray[2];

      dataArray[3] = Serial.read();  //read frame type

     

      if(dataArray[3] == 0x92){      //0x92 means I/O data sample frame

        //read the rest of the buffer and calcutate checksum

        chksum = dataArray[3];  //begin checksum with frame type

       

        for (i = 4; i <= length+3; i++) {

          dataArray[i] = Serial.read();

          chksum = chksum + dataArray[i];  //add to checksum

        }

       

        chksum = 0xFF - chksum;  //should equal zero if data is good

       

        //print dataArray to lcd if chksum == 0

        if (!chksum){           //if chksum result is zero, continue

          analogValue = dataArray[19]*256 + dataArray[20];

          lcd.clear();

          lcd.setCursor(0,0);

          //lcd.print(chksum, HEX);   //for debug

         

          for (int k = 0; k <= length+3; k++){

            if(k == 6)  {lcd.setCursor(0,1);}

            if(k == 12) {lcd.setCursor(0,2);}

            if(k == 18) {lcd.setCursor(0,3);}

            lcd.print(dataArray[k], HEX);

            lcd.print(",");

          }

        }

      }

      delay(2000);  //slow things down so you can read displayed data

    }

  }

}

  • Sign in to reply
  • Cancel
Parents
  • Nate1616
    0 Nate1616 over 13 years ago

    Hey Kevin

    I know this is a dumb question but i have seen this before but does the baud rate on the xbees match the rate in the sketch.  If the rate is higher on the xbess then you will be sending faster than what can be processed.

     

    Nate

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • kjhart0133
    0 kjhart0133 over 13 years ago in reply to Nate1616

    I'll verify the baud rate on the xbees tomorrow.  Too late now.

     

    Thanks,

     

    Kevin H.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • kjhart0133
    0 kjhart0133 over 13 years ago in reply to Nate1616

    I'll verify the baud rate on the xbees tomorrow.  Too late now.

     

    Thanks,

     

    Kevin H.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Nate1616
    0 Nate1616 over 13 years ago in reply to kjhart0133

    Hey Kevin

    Did the baud rate match?  Did you get it to work?

     

    Nate

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube