Serial communication problem

I have two Arduinos communicating through Xbee. If Arduino N°1 sends:

Serial.print('E');
     Serial.print (millis());
    Serial.print(10, BYTE);

I get alright the milliseconds on the serial monitor with the following code on Arduino N°2:

if (Serial.available() > 0) {
   val = Serial.read();
   Serial.print(char(val));

Now, I need also to send some data (simulated by the millis()/200) from Arduino N°2. So, I add some lines to the code:

if (Serial.available() > 0) {
   val = Serial.read();
   Serial.print(char(val));
  }
Serial.print('A');
  Serial.print (millis()/200);
  Serial.print(10, BYTE);

and I get a mess! Why? Thanks!

Please describe "a mess" in more detail. Does it work if you only send data from 2->1 but not in the other direction?

I’m having the same Xbee problems. People are telling me that it is an ASCII to integer conversion problem. Maybe yours is the same?

I do not send the serial.print('A') part from 2->1 but from 2 to the PC. You can see what I mean by "a mess" by comparing what I get (using Processing's PrintWriter) with the first code: 'A': 0 - 'E': 0 'A': 0 - 'E': 0 'A': 0 - 'E': 81 'A': 0 - 'E': 175 'A': 0 - 'E': 289 'A': 0 - 'E': 384 'A': 0 - 'E': 482 'A': 0 - 'E': 591 'A': 0 - 'E': 690 'A': 0 - 'E': 784 'A': 0 - 'E': 892 'A': 0 - 'E': 992 'A': 0 - 'E': 1083 'A': 0 - 'E': 1196 'A': 0 - 'E': 1295 'A': 0 - 'E': 1389 'A': 0 - 'E': 1501 'A': 0 - 'E': 1595 'A': 0 - 'E': 1694 'A': 0 - 'E': 1807 'A': 0 - 'E': 1900 'A': 0 - 'E': 2013 with what I get when adding the serial.print('A') part: 'A': 0 - 'E': 0 'A': 0 - 'E': 0 'A': 0 - 'E': 0 'A': 53 - 'E': 0 'A': 83 - 'E': 0 'A': 64 - 'E': 0 'A': 4 - 'E': 0 'A': 0 - 'E': 0 'A': 55 - 'E': 0 'A': 96 - 'E': 0 'A': 16 - 'E': 0 'A': 7 - 'E': 0 'A': 0 - 'E': 0 'A': 58 - 'E': 0 'A': 98 - 'E': 0 'A': 69 - 'E': 0 'A': 0 - 'E': 0 'A': 9 - 'E': 0 'A': 0 - 'E': 0 'A': 610 - 'E': 0 'A': 11 - 'E': 0

I think I had the ASCII/integer conversion problem Alligator mentioned (see: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256893660/0), but the

Serial.print(char(val));

solved it!