Hi, I am using an Arduino Nano connected via UART to a XBee3 Sender device that is going to send data to another XBee3 Receiver device. The TX (pin 3) of the XBee Sender is connected to the RX pin of Arduino, the RX (pin 2) of the XBee Sender is connected to the TX pin of Arduino. The 3.3V pin on the XBee Sender is connected to the 3.3V pin of the Arduino, and the ground pins are connected as well. I need to send about 50 frames with the maximum amount of bytes in each frame from the Arduino to the Sender, then get the Sender to send them to the Receiver, followed by the Receiver providing an acknowledgement that the packet is received. However, I am not sure on how to do that, help is greatly appreciated!
Sender configuration in XCTU: ID - 2015, CE - Enabled [1], NI - SENDER, AP - API Enabled[1]
Receiver configuration in XCTU: ID -2015, JV - Enabled [1], NI - RECEIVER, AP - API Enabled[1]
Digi XBee 3
Digi XBee 3 Schematic
Arduino Nano ATmega328P
I have tried a code meant for Series 2 (can't seem to find any documentation on Series 3) but does not work:
#include <Printers.h>
#include <XBee.h>
#include <SoftwareSerial.h>
/*
This example is for Series 2 XBee
Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
*/
XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41AE9DBC);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
int pin5 = 0;
int statusLed = 13;
int errorLed = 13;
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() {
pin5 = analogRead(5); // break down 10-bit reading into two bytes and place in payload
payload[0] = pin5 >> 8 & 0xff;
payload[1] = pin5 & 0xff;
xbee.send(zbTx);
flashLed(statusLed, 1, 100); // flash TX indicator
//after sending a tx request, we expect a status response, wait up to half second for the status response
if (xbee.readPacket(500)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);
if (txStatus.getDeliveryStatus() == SUCCESS) {
flashLed(statusLed, 5, 50);
Serial.println("SUCCESS");
} else {
flashLed(errorLed, 3, 500); //the remote XBee did not receive our packet. is it powered on?
Serial.println("NOT RCVD");
}
}
} else if (xbee.getResponse().isError()) {
Serial.print("ERROR");
//nss.print("Error reading packet. Error code: ");
//nss.println(xbee.getResponse().getErrorCode());
} else {
// local XBee did not provide a timely TX Status Response -- should not happen
flashLed(errorLed, 2, 50);
}
delay(1000);
}
/*
//turn on external LED when data is available (does work)
void setup() {
pinMode(8, OUTPUT);
digitlWrite(8, LOW);
Serial.begin(9600);
}
void loop() {
for (int i = 0x01; i < 0x33 ; i++){
Serial.println(i, HEX);
delay(100);
}
if (XBee.available() > 0){
delay(1);
digitalWrite(8, HIGH);
} else {
digitalWrite(8, LOW);
}
}
*/