Shop OBEX P1 Docs P2 Docs Learn Events
pc to arduino using Xbee — Parallax Forums

pc to arduino using Xbee

ahmed.elhelowahmed.elhelow Posts: 1
edited 2012-08-29 07:32 in Accessories
hi...
I have arduino mega 2560 R3, Xbee arduino shield, 2 of Xbee modules (modem type XBP24BZ7), USB-XBEE Adaptor. I have configured first Xbee as coordinator at and second one as end device at. I have succeeded in sending string from arduino to X-CTU terminal (Xbee software) using this code
void setup(){
    Serial.begin(9600);
}
void loop(){
    // handle serial data, if any
    Serial.println("hello world");
}

But I can not receive any string from X-CTU terminal to arduino. I have tried many arduino codes such as :
// this is where we will put our data
int myData = 0;
void setup(){
    Serial.begin(9600);
}
void loop(){    
    if(Serial.available() > 0){
        Serial.println(333);
        myData = (int)(Serial.read());
        Serial.println(myData + 777);
        delay(1000);
    }
}

and this too
#include <XBee.h>
XBee xbee = XBee();
void setup() { 
  xbee.begin(9600);
}
void loop() {
  //attempt to read a packet    
  xbee.readPacket(5000);
  
  if (xbee.getResponse().isAvailable()) {
    // got something
    Serial.println("something");
    if (xbee.getResponse().getApiId() == ZB_IO_SAMPLE_RESPONSE) {
      xbee.getResponse().getZBRxIoSampleResponse(ioSample);
      
      Serial.print("Received I/O Sample from: ");
      
      Serial.print(ioSample.getRemoteAddress64().getMsb(), HEX);  
      Serial.print(ioSample.getRemoteAddress64().getLsb(), HEX);  
      Serial.println("");
      
      if (ioSample.containsAnalog()) { 
        Serial.println("Sample contains analog data");
      }

      if (ioSample.containsDigital()) {
        Serial.println("Sample contains digtal data");
      }      

      // read analog inputs
      for (int i = 0; i <= 4; i++) {
        if (ioSample.isAnalogEnabled(i)) {
          Serial.print("Analog (AI");
          Serial.print(i, DEC);
          Serial.print(") is ");
          Serial.println(ioSample.getAnalog(i), DEC);
          
        }
      }

      // check digital inputs
      for (int i = 0; i <= 12; i++) {
        if (ioSample.isDigitalEnabled(i)) {
          Serial.print("Digital (DI");
          Serial.print(i, DEC);
          Serial.print(") is ");
          Serial.println(ioSample.isDigitalOn(i), DEC);
          
        }
      }
    } 
    else {
      Serial.print("Expected I/O Sample, but got ");
      Serial.print(xbee.getResponse().getApiId(), HEX);
      
    }    
  } else if (xbee.getResponse().isError()) {
    Serial.print("Error reading packet.  Error code: ");  
    Serial.println(xbee.getResponse().getErrorCode());
  }
  Serial.println("receiving not work");
  delay(1000);
}

But receiving never works.

What should I do to solve this problem?

Best regards

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-29 07:32
    Sorry, we can't really help you with your Arduino code. This is primarily a support forum for Parallax microcontrollers like the Basic Stamp and the Propeller. There's some support for the Arduino and a number of sensors that Parallax makes and sells, but the xBee support is mostly for the Parallax microcontrollers and the 802.15.4 xBees. Try the Digi support forums and the Arduino support forums.
Sign In or Register to comment.