Float I2c

Thanks for the reply!

It works correctly using the single call to Wire.write(). If I split it into two calls it fails:

eg

Wire.write(vals[0]);
Wire.write(vals[1]);

Produces

Received 2 bytes.
Received: 172 .
Received: 255 .

Is there something about the Wire library that means only a single write() should be used in an interrupt? I2C_writeAnything() uses multiple Wire.write() calls in a for-loop, so that would mean it can't be used in an onRequest handler.

Perhaps I could modify it to fill a byte array, then send using a single write() call, like this:

float someFloat = 1.2;
byte vals[4];

byte * p = (const byte*) someFloat;
unsigned int i;
for (i = 0; i < sizeof someFloat; i++)
  vals[i] = *p++;

Wire.write(vals, 4);

Or something like that?

-Eric