If you receive a misfire with zero bytes, then you still do something in the onReceive handler.
Can you transfer a package of binary data of a fixed size ? That is easier.
volatile an array or a struct // for example 18 bytes in size
volatile bool newData;
void receiveEvent( int howMany)
{
if( howMany == 18) // expecting 18 bytes, ignore everything else
{
copy the data to the array or a struct
newData = true;
}
}
Your receiveEvent() has:
-
while while(0 < Wire.available())Why would you use a while-statement ? How many times do you want to read the package of data ? -
0 < Wire.available()Who on earth uses that ? If I say it out loud: "while zero is lower than the amount of available data". Huh ? -
printRequest = 1;Outside the while-statement ? Why ? -
#define MAX_MESSAGE_LENGTH 16Your data length is 18 for the I2C bus. The sketch is easier if you transfer 18 bytes over the I2C bus and use 18 bytes in the sketch.
We don't use readable ASCII for the I2C bus.
A fixed size of binary data is achieved this way:
float xyzData[3];
or with a struct:
struct myStruct
{
byte command,
int16_t temperature,
float xyzData[3],
}