Need Help reading data from Sensor using I2C

I am trying to read a sensor using I2C, i am new to this and i only keep getting response as -1.
Th steps described in the datasheet are as per the below images.

my code is as under:

#include <Wire.h>

int X0;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  delay(100);

  Wire.beginTransmission(0xDA); 
  Wire.write(0x08);
    
  Wire.endTransmission();
  Wire.requestFrom(0xDB,1);
  X0 = Wire.read();
  Serial.print("X0= ");
  Serial.print(X0);
  Serial.print("\n");
  
  delay (500);
}

void loop() {

}

I would appreciate inputs on how to get this done.

Many sensors have libraries that can be included in your sketch to help interface with that particular sensor. I would try to find one for your sensor then run it with the example sketch usually provided by the library.

The Wire library expects the 7bit I2C slave address in the beginTransmission() and requestFrom() methods, not the complete first byte of the protocol.

@Pylon, thanks.
I updated the code and changed the address to 0x6D (7 bit), it works now.

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