You can actually send any datatype via I2C since each and every datatype comprises of individual bytes.
While this library may make things easier, it’s always best to first know/understand the fundamentals before using “black-box-magic”. This way you’ll be armed to tackle any eventual bumps or shortcomings of any given library and may even be able to adapt a library to fit your needs.
e.g. in order to send an
int you’d just write
Wire.write((const uint8_t*)&i, sizeof(i));
And since the
TwoWire class inherits from
Stream you can also use this to read data back
you should be set without any additional library.
(endianness may be something that requires extra attention tho’)
BTW, in principle this also is what the “library” does (also without accounting for endianness - which may be your issue - what datatype do you intend to transfer) but IMO the use of the “buffer read” function seems more refined than the loop approach.
However, these templated functions might be worth considering to be added to the
Stream class as they might be quite useful for all stream based classes.
@avtolstoy, what’d you think?
Might even be worth a contribution to the Arduino