Home/Support/Support Forum/AtCommandRequest example for Arduino not working- Can't change D3 pin value

AtCommandRequest example for Arduino not working- Can't change D3 pin value

0 votes
I'm using the arduino API library and trying to perform AT commands. I've had plenty of luck before using remote AT commands, but for some reason this nearly identical process won't work.

I'm not actually using software serial. I'm loading the program to the board, running it with the Xbee attached, and then checking it in XCTU afterward to see if the parameter has changed. There should be no conflicts with serial ports.

All I get with this code is a '~' (7E, the start delimiter byte) character that shows up in the serial port. Then the script progresses no further and the command is not executed.

I thought it had something to do with my Arduino so I trued a Nano (I had one lying around) instead of an Uno.This time, It looks like I got the whole string out, but the radio still does not respond or change values.

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

// Define SoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);

XBee xbee = XBee();

// serial high
uint8_t D3Cmd[] = { 'D', '3' }; //D3
uint8_t low[] = { 0x04 };////for DI03 pin parameter

AtCommandRequest atRequest = AtCommandRequest(D3Cmd, low, 1);

AtCommandResponse atResponse = AtCommandResponse();

void setup() {
// start soft serial

// Startup delay to wait for XBee radio to initialize.
// you may need to increase this value if you are not getting a response

void loop() {





while (1) {};

void sendAtCommand() {
nss.println("Sending command to the XBee");

// send the command

// wait up to 5 seconds for the status response
if (xbee.readPacket(5000)) {
// got a response!

// should be an AT command response
if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {

if (atResponse.isOk()) {
nss.print("Command [");
nss.println("] was successful!");

if (atResponse.getValueLength() > 0) {
nss.print("Command value length is ");
nss.println(atResponse.getValueLength(), DEC);

nss.print("Command value: ");

for (int i = 0; i < atResponse.getValueLength(); i++) {
nss.print(atResponse.getValue(), HEX);
nss.print(" ");

else {
nss.print("Command return error code: ");
nss.println(atResponse.getStatus(), HEX);
else {
nss.print("Expected AT response but got ");
nss.print(xbee.getResponse().getApiId(), HEX);
else {
// at command failed
if (xbee.getResponse().isError()) {
nss.print("Error reading packet. Error code: ");
else {
nss.print("No response from radio");
asked Sep 14, 2017 in IEEE 802.15.4 by Flieronymus New to the Community (2 points)

Please log in or register to answer this question.

1 Answer

0 votes
You can't monitor the serial port that the radio is on and have the processor talk to the radio. You can do one or the other.
answered Sep 14, 2017 by mvut Veteran of the Digi Community (15,413 points)
Its the same Nano. Tx works, Remote AT commands work, but AT commands do not work.
What is the API frame you are sending over that is not working?
It should be 7E 00 05 08 01 44 33 04 7B

But I have no view of what the API library is sending except for the gibberish I see in my serial pane when not connected to Xbee. It looks like ~(strange character)(strange character)(null)D3(strange character){.

Here s that code again, this time simplified even further:

#include <XBee.h>  

XBee xbee = XBee();

uint8_t D3[] = { 'D', '3' };
uint8_t high[] = { 0x05 };/////for DI03 pin parameter
uint8_t low[] = { 0x04};////for DI03 pin parameter

AtCommandRequest AtRequest = AtCommandRequest();
AtCommandResponse atResponse = AtCommandResponse();

void setup()



void loop()
The gibberish you are seeing is the ASCII form of the hex data.  Try using a terminal that has a Hex viewer and you will see it.

Note that sending code snippets without having any context as to what a function is doing does not really help as it does not tell you what is being sent.
I know what the gibberish is. I don't have to see it. It only needs to be read by the Xbee.

"Note that sending code snippets without having any context as to what a function is doing does not really help as it does not tell you what is being sent."

Are you serious? I'm using THE Xbee API library for Arduino. We all know what it's supposed to be doing and how it's supposed to work.

Copying the frame generated in the XCTU frame generator in hex and converting it to ascii, it's exactly the same frame as what the library is putting out. Just like I said five times, the frame is being generated perfectly. So why won't the Xbee respond? If you don't have an answer, then why bother responding if not just to try and make yourself look smart?