Serial communication questions!

Hey there i have a few questions about serial communication with arduino. I have used it several times before with xbee's and not. But i dont fully understand what im doing.

First off when im printing or writing a integer to Serial what am i acctually printing is it a char? I know about ascii values but still dont get what im actually printing. So if i print a value such '123' is that actually a string and not a number?

How do i handle this information on the reieving arduino? Do i treat the data recieved as strings and chars?

Say i use this sample here:

int joyX = getValue(JoyX);
  int joyY = getValue(JoyY);
  
  
  Serial.print(joyX);
  Serial.print(",");
  Serial.print(joyY);
  Serial.println();

What am i actually sending to the serial monitor?

(JoyX and JoyY are somewhere between 80 - 200.)

And last question, when should i use serial.write() instead of serial.print() or serial.println()

Thank you!!

Serial.print(joyX);
  Serial.print(",");
  Serial.print(joyY);
  Serial.println();

Convert the "int" value "joyX" to its ASCII decimal representation, and send it to the serial port.
Send an ASCII comma to the serial port.
Convert the "int" value "joyY" to its ASCII decimal representation, and send it to the serial port.
Send a carriage-return/line-feed to the serial port.

Didnt quite answer my questions and also how would i convert a three digit number into ascii?

Thanks

What am i actually sending to the serial monitor?

It answered that question.

how would i convert a three digit number into ascii?

int x = 768;
Serial.print (x);

would convert a three digit decimal number"x" into ASCII.

The demos here, here and here may help

If you use Serial.print(myNumber) you are sending the number as text - the characters "112", for example.

You could also use Serial.write(112) which will send a single byte with a value of 112 - which also happens to be the Ascii value for 'p'

On the Arduino an integer is two bytes so if you want to send its binary value you have to figure out the values of the two separate bytes and send each of them with Serial.write()

And, obviously, the program receiving the data has to be designed to deal with whatever is sent.

...R

Thank you so much!

What would the recieving code look like? How do you recieved stuff that has been Serial.write() 'en ?

Are the values im printing here not ASCII?
i

nt joyX = getValue(JoyX);
  int joyY = getValue(JoyY);
  
  
  Serial.print(joyX);
  Serial.print(",");
  Serial.print(joyY);
  Serial.println();

Are the values im printing here not ASCII?

They are because you are using print(). If you used write(), the values sent to the serial port would be binary.

lele_gricc:
What would the recieving code look like? How do you recieved stuff that has been Serial.write() 'en ?

My examples do both

...R