can't send 2 digit from arduino 1 to other using XBEE s2

hello i have 2 xbee s2 the firmware is api mode API. 1 xbee s2 is a coordinat API-2 and the other Router API-2. so the problem is i send a random data integer int a=random(99); oh btw i use arduino in 2 side so arduino1->xbee(tx)->xbee(rx)->arduino2. back to the problem is when i look in serial monitor arduino 2 it just receive 1 digit number, like if i send a=72 then it just receive the first number, it’s 7. i used andrew library
xbee-s2 arduino

Series2_Rx.ino (3.33 KB)

Series2_Tx.ino (2.75 KB)

Why are the XBees connected to the hardware serial port? Get them off the hardware serial port so that you can use it for debugging.

You put two bytes in payload on the sending end. Then, on the receiving end, you use

        analogWrite(dataLed, rx.getData(0));
        data1=rx.getData(0);
        Serial.print("Data :");
        Serial.print(data1);

How many bytes does getData() read? What does the argument to getData() mean? What is the return type from getData()?

Hint: 1, an offset, uint8_t.

You are sending two bytes and reading one byte.

how to fix the code? i’m really confused. i.m try to fix the code like this but it didn’t work to.in the sender i use “Q” for the mark. oh btw thank you for answerng me before :slight_smile: :slight_smile:

Series2_Rx.ino (3.94 KB)

how to fix the code?

byte b0 = rx.getData(0);
byte b1 = rx.getData(1);

int val = (int)b0 << 8 + b1;
analogWrite(dataLed, val);

hi PaulS Thank you for the answer. i try your code “int val = (int)b0 << 8 + b1;” but it dosen’t work the result always zero , so i use this.

long f=0;String inString = “”;
for(int i=0;i<rx.getDataLength();i++){
/long a;
a=rx.getData(i)+‘0’;
a
=pow(10,(rx.getDataLength()-(i+1)));
f+=a;*/
inString += (char)rx.getData(i);
}

Serial.print("\n");
Serial.print(inString.toInt());

Did you change the sender to send ASCII data, too?