Read Multiple bytes from I2c

I am trying to read from a sensor (X,Y,Z) using a I2C communication. I want to read all 3 axis in one I2C read. I’m stumped as to how to do this. So far what I think I know is:

Wire.beginTransmission(I2C_ADCAddress);
Wire.write(REG_ADDR_RESULT); // send register to start read
Wire.endTransmission();
Wire.requestFrom(I2C_ADCAddress, 2);
byte buff[2];
Wire.readBytes(buff, 2); // read value of the 'result' register

My understanding is I2C_ADCAddress is the sensor I2C address. 
REG_ADDR_RESULT is the register I need to start my read from.
Wire.requestFrom(I2C_ADCAddress, 2)  here I am requesting 2 bytes.

Here I need to get into a loop and read a byte each time until I run out of data
while (Wire.available()) {         //are there bytes to receive.
  in_char = Wire.read();           //receive a byte.
  sen_data[i] = in_char;            //load this byte into our array.
  i += 1;                          
  if (in_char == 0) {              //if we see that we have been sent a null command.
    i = 0;                         //reset the counter i to 0.
    Wire.endTransmission();        //end the I2C data transmission.
    break;                         //exit the while loop.
  }

THANK FOR ANY HELP YOU CAN SUGGEST.....

It’s impossible to say for sure without knowing which sensor you are using. But with the LIS3DH I read six bytes and then decode them to get the X, Y, Z.

Thanks Rick..........I'll give it a shot.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.