pc to arduino using Xbee
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
But I can not receive any string from X-CTU terminal to arduino. I have tried many arduino codes such as :
and this too
But receiving never works.
What should I do to solve this problem?
Best regards
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