The simplest way is to use a number of Serial.print (one for each variable) to send the variables as text and use e.g. a comma as the separator. You can have a look at Serial Input Basics - updated for the receiving side and write a matching function for the sending side.
The sending of binary data is simple; cast to a byte pointer and use serial.write. Below demonstrates
struct MYDATA
{
char text[10];
byte aByte;
};
MYDATA dataToSend =
{
"abc",
0x30 //
};
void setup()
{
Serial.begin(57600);
Serial.write((byte*)&dataToSend, sizeof(dataToSend));
}
void loop()
{
}
(byte*)
is the cast, &
indicates the address of the variable dataToSend
.
There are some pitfalls
- Sending binary data of variables like int has a dependency on the the endianness of the two systems. Sending text is easier from that perspective.
- Synchronisation of binary data is more complex than of text. Reason is that it's more difficult to differentiate between actual data and a 'beginning fo packet'.