Sending int over XBee

Hey

I have a programming problem in my small project. I try to send an integer over XBee to another Arduino using Serial.print(). It works quite well but there's a problem in the receiving end.

The first Arduino sends an integer like this Serial.print(25);

The second Arduino receives it but it looks like this when testing with Serial.println(incomingByte);

2
5
2
5

How can I combine those integers so it would look like this?

25
25

The loop code:

void loop() {
  if(Serial.available()>0){
    incomingByte = Serial.read() - '0';
    Serial.println(incomingByte);
  }
}

So basically I want to combine those two integers (2 and 5) into one (25) and use that 25 later on.

Thanks

The second Arduino receives it but it looks like this when testing with Serial.println(incomingByte);

That is exactly what it should do, given the way that you have written the code.

So basically I want to combine those two integers (2 and 5) into one (25) and use that 25 later on.

Several choices. One is not to have two integers. Instead, add the value of the second character, as an integer to the first integer. Perhaps you've noticed that 25 = (2 * 10) + 5.

Another is to save all the characters in an array, and use atoi() to convert the string to an int.

Multiplying by 10 works, but then I wondered what if I wanted to send single digit integers aswell. I would have to separate the numbers somehow and I found this http://www.gammon.com.au/forum/?id=11425 The last example 'How to send and receive numbers' was just what I was looking for :)

HEy Turbotube,

after the guys helped me a lot in this Forum i wanna help as well. Its not that much what i can do because im at the beginning, but here are some good sites which helped me a lot when i did stuff with the XBEEs

http://www.electrojoystick.com/tutorial/?page_id=25 http://forum.arduino.cc/index.php?action=printpage;topic=77219.0 http://creativecoding.uni-bayreuth.de/tools/arduino/arduino-patterns/ http://arduinobasics.blogspot.de/search/label/AnalogRead