I2C Interface access

andykim117

New Member
Joined
Feb 25, 2025
Messages
1
Reaction score
0
Credits
14
I try to control a device by the I2C interface.

But I guess that its interface is reserved by the kernel driver.

# i2cdetect -y -r 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

In this case can't I control this device through the i2c interface?

Thanks
 


Normally you don't access it this way. You would use a low level language like C/C++.

Code:
#include <Wire.h>

const int TMP102_ADDR = 0x48; // I2C address of the TMP102 sensor

void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(TMP102_ADDR);
  Wire.write(0x00); // Point to the temperature register
  Wire.endTransmission();
  
  Wire.requestFrom(TMP102_ADDR, 2); // Request 2 bytes of data

  if (Wire.available() == 2) {
    int tempData = Wire.read() << 8 | Wire.read();
    float temperature = tempData * 0.0625; // Convert to Celsius
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");
  }
  
  delay(1000); // Wait for 1 second before the next reading
}
 



Top