For low-level reads like this the Arduino example you’re using is a little misleading.
You have to tell the device what register you want to read from in the form of a write
Then read the desired number of bytes.
Review this document
A complete read transaction has
- 1st byte: a start Bit followed by Device address, and a
write
bit - 2nd byte: the register to be read from
- 3rd byte: a repeat start, the Device Address, and a
read
bit - 4th byte: data is clocked from the device to the controller
I think you might want to try my (untested, GPT generated) code:
#include <Wire.h>
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize I2C communication
Wire.begin();
}
void loop() {
// Request one byte from the device at address 0x42, from register 0x12
Wire.beginTransmission(0x42); // Start communication with the device at address 0x42
Wire.write(0x12); // Specify the register address you want to read from
Wire.endTransmission(false); // End transmission, but don't release the I2C bus
Wire.requestFrom(0x42, 1); // Request 1 byte from the device
while (Wire.available()) { // Wait for the data to be available
byte data = Wire.read(); // Read the byte
Serial.print("Received data: ");
Serial.println(data, HEX); // Print the data in hexadecimal format
}
delay(100)
}