Reading bytes from BNO055 motion sensor in chunks vs. all at once via I2C

Status
Not open for further replies.

EBRAddict

Member
Why not read all 44 motion bytes (or any subset that you need as long as they are contiguous) in one transaction?

I'm using the Teensy BNO055 library from kriswiner/onehorse on Github https://github.com/kriswiner/BNO-055. I have the device working.

In this library the sensor data is being read in chunks, i.e. 6 bytes for acceleration, then 6 bytes for gyro, etc., as separate I2C transactions. There is material timing overhead in the I2C stop command each time a transaction is concluded, added together it's in the milliseconds range.

The official Bosch library reads in chunks like this, as does the Adafruit library. Libraries for other sensors like the MPU9250 and the LSM303 do so as well. Am I missing something?
 
No, I don't think you're missing anything. It looks fine to do it that way.

As you say, you would get much more efficient use of I2C. The only trade off is the ever so slightly more complicated unpacking of the data. I guess that is why the library writers do it the way they do. Providing a function that returns an X or Y parameter as a single return variable is a lot easier to explain to users than asking them to provide the address of a buffer of n bytes that they would need to unpack themselves. Also dealing with the added issues of users that don't provide a big enough buffer or don't understand pointers well enough to use the APIs. etc. etc.

Simple functions will keep the most number of users happy, and most wont care about the less efficient use of I2C.
 
You might need to edit Wire.h for a longer buffer. The default is only 32 bytes, which will cause you trouble when reading 44 bytes at once.
 
Status
Not open for further replies.
Back
Top