serial send/receive integer

hi folks,

I'm communicating with my arduino chip over serial
Everything is fine and I can send and receive numbers between 0 and 255.

Now I'am trying to send/receive numbers between 0 and 5000.

I understood that an interger is 2 bytes. Is it possible to explain how to use atoi and itoa with an example.

many thanks and sorry for my poor enlish.

antoine

5000DEC = 1388HEX, so you will have to receive it as 2 bytes and put it together, maybe like this:

thank you for yout fast reply,
but this is complete chinese for me. is it possible to detail / clarify your words.
thanks again,

tony

Serial.print() can be given ANY type so you can use

int value = 5000;
Serial.print(value);

or

long value = 5000;
Serial.print(value);

or, or, or.

I hope you understand what I mean.

Jan

There are two ways to send data to the serial port - ascii and binary.

Sending binary data is done one byte at a time. If the type being sent is larger than a byte, such as an int or a float, the appropriate number of bytes needs to be send, after extracting the appropriate bytes from the larger type. This is typically done using highByte() and lowByte() for integers or unions for larger, or non-integer, types.

Sending ascii data is automatic. If the variable containing the data to send is an int, the value is converted to a string, and the characters that make up the string are sent in order.
int val = 1750;
The value is sent as '1', '7', '5', and '0'.

On the receiving end, the characters are collected in an array, NULL terminated of course, and the atoi() function is used to convert the string back to an integer. Similar functions are available for other types.

More details about how you want to send the data, and the types of data to send would be useful.