Xbee API router with arduino producing strange characters when sending data

i have 2 arduino one coordinator in API and one router in Api. watching the serial screen of the router appear strange characters when the code reachs the xbee.send() method
Could anyone tell me why are these characters appear?

Here is the source code of the router:

const int dimout=11; 
const int ldr=A0; 
const int relay=4;
float sensorValue=0,pwmValue1=0,pwmValue2=0;
float Volt,Lux,Difference;
float VDifference,d=2;
uint8_t SData[4];
XBee xbee=XBee();
XBeeResponse response=XBeeResponse();
ZBRxResponse zbRx=ZBRxResponse();
XBeeAddress64 rmtAddress=XBeeAddress64(0x0013a200,0x040b33b0c);
ZBTxRequest zbTx=ZBTxRequest(rmtAddress,SData,sizeof(SData));
int state=1;
long previousTime=0;
unsigned long start=0;
long timeStep=180000;// 15 lepta
long interval=2000*60*60;//2 wres
  float f;
  byte b[4];

void setup(){

void loop(){
      Serial.println("I received an RX packet");
       if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED){
         Serial.println("Packet acknowledged");
         Serial.println("Packet not acknowledged");
      Serial.println("The received Data length is");
         for(int i=0;i1){
        for(int i=0;itimeStep){
      Serial.println("Automatic Control");
      Serial.println("sensor value=");
      Lux=13.449*exp(1.0055*Volt)/pow(d,2);//pali o tupos ths sunarthshs
      VDifference= (log(Difference)-log(13.449))/1.0055;// antestrammenos o tupos ths sunarthshs ga na dinei volt
      Serial.print("The amount of light at your workspace is:");

and a screenshot of the serial screen of the arduino.
Your text to link here…

Thanks in advance

What is the data you are seeing? Could it be the Hex values of the API frame or the ASCII values of the Hex API frame that you are seeing?

I am having the same problem and it is most probably the ASCII value of the hex api frame. Do you have any solution?

Yea you need to provide the Hex values with the AT commands and not issue it as an ASCII value.

Hi, i’m having similar issue but i didn’t quite understood the solution (i don’t know much of xbees).

One xbee is connected to an ArduIMU V3 to send the data, and the coordinator is connected to my computer with an explorer. I’m using API mode.

I’m receiving a strange string of data while sending a variable value.

Here is what’s happening, i’m just sending the number 36 in 0.5Hz ratio.

Your text to link here…

The code uploaded to the ArduIMU:

#define RLED_PIN  5
#define BLED_PIN  6
#define YLED_PIN  7

long timeNow = 0;
long timer_1 = 0;
long timer_2 = 0;

int cicly_led_blue = 0;
int x = 0;

void setup() 
  pinMode(RLED_PIN,OUTPUT); // Red LED
  pinMode(BLED_PIN,OUTPUT); // Blue LED
  pinMode(YLED_PIN,OUTPUT); // Yellow LED
  x = 36;

void loop() 
  timeNow = millis(); 

  if((timeNow-timer_1) >= 1000) // LED loop runs at 1Hz
    timer_1 = timeNow;
  if((timeNow-timer_2) >= 2000) // Sending data loop runs at 0.5Hz
    timer_2 = timeNow;

void output_serial()

void led_blue_control() 

Thanks in advance.

From the looks of it, you are trying to read ASCII data instead of Hex data. From the quick search I did, there are several answers on Arduino’s support forum site for how to do this.


Actually this is just a test code. I’ve tried many different things to try to solve it, but none have succeeded.

Things that i’ve tried:

  • Different sets of Baud Rates;
  • Different sending methods (Serial.write, Serial.print(,HEX), Serial.print(,BIN));
  • Change the coordinator;
  • Change the transmitter;
  • Change the explorer;
  • Change the coordinator AND the transmitter;

About the Arduino forums, i did a search too but found nothing that helps. Yes, there are many topics with the same problem being reported, but none of them propose a solution that solves the problem at the end.

Any other suggestions? Thanks for your reply.

Try http://www.codeproject.com/Questions/236017/Correct-Way-to-write-Hex-Values-to-Serial-port-thi


Hm, didn’t saw any useful information on those links. I’m not sending any ASCII value beyond the additional characters in that range (127).

Well, as said in the earlier comment i’ve already tried multiple ways of sending data, with both Serial.write and Serial.print.

The thing is, when i receive the data through the FTDI cable everything goes perfect. But when i send the data through the XBee those strange characters are added. I do receive the correct information and i’m able to understand it, but it’s together with those undesired characters.

Thanks for your help and time looking for those links btw. But that doesn’t seems the same situation i’m experiencing.

The characters you are referring to are Hex values because the XBee is in API mode. Try taking it out of API mode and you will not see the characters you are referring to.

Indeed the characters are gone when i don’t use API mode. So there is no way to get rid of those characters? I mean, if i use API mode those characters will be there no matter what?

Yes they will be there as you are seeing the ASCII representation of the Hex API packet. You will need to talk to your processor support to find out how to view the data in Hex instead of ASCII if you want to use API mode and to be able to view the RAW Hex API frame.

Many thanks mvut. I was confused about API mode, but now with your answers and taking some time to think about it i manage to understand what’s going on.

But i have another question now. XBee receives RF data over the serial port in ASCII encoding. But that’s not good at all for me because in this way the length of data i wanna transmit is duplicated. Let me try to explain better.

If want to send a value over the serial with the XBee, for example 255 decimal. It’s the same as FF hexadecimal and has a length of 1 byte. If i send this over the serial port and view the result in XCTU i get an ASCII encoding of the “FF” as 46 46 (hex code). This way one byte of information (FF) turned into two bytes because of the ASCII interpretation of 1 byte/character.

There is any way to transmit information without using ASCII encoding?

That is not the radio doing this. If you want to send Hex data using XCTU to verify everything is working, you need to use the Send packet function and Hex option. Then put in your 0xFF data field. You will see that this will then do what you wanted.

Yes, it worked! Many Thanks mvut. Sometimes i don’t see the obvious in these things.

Thanks again for your answers and sorry if i bothered you too much with my questions.

See ya.