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()
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.
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.