I want to send some potentiometer, nunchuk and butten-state data over Xbee to an other arduino device (Robot) it's not too much data but it would need to be send quite often to keep the nunchuk and robot in sync.
Okay, so maybe 5-10 bytes, 50-100 times/second (or less)?
There are several things to consider. They may get out of synchronisation because one sends data faster than the other can receive data, or data might get corrupted in transit.
I think Zigbee does error correction, so that isn't my dominant worry. (Please correct me if I'm mistaken)
The easy way to send data is to use ordinary printable ASCII.
This is easier to debug compared to binary because you can read it. It's feasible for you to type it, making testing even easier.
Also, because many of the possible binary values are not used, it provides a dumb sort of error checking.
Okay, so the next question is whether the communications is two way. It is more complex to get two ends to agree and handshake than simply pump data in one direction. For real-time data, the sort of need you outline, I'd be very tempted to try one-way comms. I'm assuming that if the receiver detects data loss, it will just ignore some data, and pick up when it can. With real-time communications it is often more important to have the most up to date data than try to correct for an error and get old, stale, data correctly.
Normal techniques for comms (i.e. not security focused), have to solve a few problems.
When sending structured data (i.e. not just a sequence of dumb bytes), it should try to make it easy for the receiver to separate the stream of bytes into separate data values, and to detect which bytes have which meaning (i.e. which value they belong to).
It is very easy to overcomplicate this.
(Some folks went nuts with XML, and IMHO, pushed a pile of extra stuff into communication streams which was never needed, but some folks disagree)
It is helpful, if the length of each data can vary. Fixed length fields are great if the comms is very reliable, i.e. from hard disk to memory, but less useful for unreliable communication because there still needs to be a way to detect lost bytes.
I would suggest a simple path is to send the data values with a single byte maker between each one to say what the data is:
e.g. P375A6B0C678;
the letters say what a number means, maybe P for potentiometer, etc. The ';' is the end of the set of data items, or 'packet'.
I'd likely send button open and close as '0' and '1' because that translates directly to what the Arduino uses, and you only need one way to get at data, it's all numbers.
[edit]If all the data is numbers, and numbers only, it is even easier when the 'tag' for the name of the data comes after the number, because the number (the data) is collected in a single way, then immediately used when the 'tag' is received.
If there is more than one type of data, the 'tag' is usually enough to decide what type it is, so put the tag in front of the value (data).
These are examples of a classic comms technique called 'Name Value pairs'[/edit]
The single letters are easy to decode using a switch or if tests.
The numbers are always numbers, so that is straightforward, and they can be different lengths (up to 31 bits of data) with only one piece of code to decode it.
The letters and ';' make it easy to detect data loss and resynchronise if data gets lots.
I didn't use any control characters, like end of line, because they are hard to create from the serial monitor, so control characters make communication harder to test by hand.
[edit]Unless testing by hand is an issue, I would use '\n' as a record or packet separator.
That is for a bunch of reasons:
a. I am a *nix person, so I have lots of programming idioms in my fingers
b. most people recognise what it means
c. A file of test data is easy to read
d. A very dumb program can act as a receiver, store data in EEPROM, and play it back to a serial monitor
e. dumb comparison programs like cmp or diff work well to compare intended output with actual output for automated testing.
I'd probably make the packet terminator a variable in the program so that I could change my mind at a later date.
Maybe this is an argument for a fancier serial monitor
[/edit]
HTH
I hope there is not to much confusion because of my lack of english...
It is very kind of you to accept and work around my lack of your language. Thank you.