Home/Support/Support Forum/Sending Data from Arduino to XCTU

Sending Data from Arduino to XCTU

0 votes
Hi everyone!

I have 2 XBee Series 1 modules, both of which are configured in API mode (API mode = 1) in XCTU. I have configured one XBee module as the Coordinator, which is attached to my PC and is interfacing with XCTU. The other XBee module is connected to an Arduino Uno, configured as an End Device.

For the Arduino Uno, for a start, I copied the code from the XBee library by andrewrapp and ran it in my Arduino program. To remove the need to shift the bytes/split them, I have decided to send the number "1" in payload[0]. I have provided the code here for everyone's easy reference.

However, when I opened the connection for my Coordinator on XCTU, I did not receive any printouts on the screen, and when I checked Arduino, it reported that it did not receive any response from the Coordinator attached to my PC.

May I ask why is this happening and what should I do to remedy it? Thank you so much!

The Arduino Code (Credits: andrewrapp):

#include <XBee.h>
#include <SoftwareSerial.h>

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };

// 16-bit addressing: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(0x5678, payload, sizeof(payload)); //5678 is the MY 16-bit address on XCTU

TxStatusResponse txStatus = TxStatusResponse();

int pin5 = 0;

int statusLed = 13;
int errorLed = 12;

void flashLed(int pin, int times, int wait) {

for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);

if (i + 1 < times) {
delay(wait);
}
}
}

void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
Serial.begin(9600);
xbee.setSerial(Serial);
}

void loop() {

// start transmitting after a startup delay. Note: this will rollover to 0 eventually so not best way to handle
if (millis() - start > 5000) {
pin5 = 1;
payload[0] = pin5;

xbee.send(tx);

// flash TX indicator
flashLed(statusLed, 1, 100);
}

// after sending a tx request, we expect a status response
// wait up to 5 seconds for the status response
if (xbee.readPacket(15000)) {
// got a response!

// should be a znet tx status
if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
xbee.getResponse().getTxStatusResponse(txStatus);

// get the delivery status, the fifth byte
if (txStatus.getStatus() == SUCCESS) {
// success. time to celebrate
flashLed(statusLed, 5, 50);
} else {
// the remote XBee did not receive our packet. is it powered on?
flashLed(errorLed, 3, 500);
}
}
} else if (xbee.getResponse().isError()) {
//nss.print("Error reading packet. Error code: ");
//nss.println(xbee.getResponse().getErrorCode());
// or flash error led
} else {
// local XBee did not provide a timely TX Status Response. Radio is not configured properly or connected
flashLed(errorLed, 2, 50);
Serial.println("TO");
}

delay(1000);
}
asked Feb 16, 2018 in IEEE 802.15.4 by galaxy_twirl New to the Community (0 points)

Please log in or register to answer this question.

...