Unable to read ID Register directly
Hello,
As suggested in my last post here, I am trying to read the ID Value of a VL53L1X sensor. I get a read failure when I attempt to read the register. Strangely, I have slightly modified code that I am using to read the ID register of a VL53l0X which I am able to run successfully. Further, I know I do not have a hardware or wiring problem because I am able to use the sensor for ranging just fine. I have copied my basic ESP32 Arduino sketch below, any ideas what I'm doing wrong? Thanks in advance
#include <Wire.h> // Include Wire library for I2C communication
// I2C address of the VL53L1X sensor (0x29)
#define VL53L1X_ADDRESS 0x29
// Register addresses
#define VL53L1X_IDENTIFICATION_MODEL_ID 0x010F // Model ID register (lower byte)
#define VL53L1X_IDENTIFICATION_REVISION 0x0110 // Model revision register (upper byte)
void setup() {
Serial.begin(115200);
Serial.println("Starting VL53L1X sensor test (I2C access)");
// Read ID registers directly using I2C communication
uint8_t model_id = readRegister(VL53L1X_ADDRESS, VL53L1X_IDENTIFICATION_MODEL_ID);
Serial.print("Model ID: ");
Serial.println(model_id, HEX);
uint8_t revision_id = readRegister(VL53L1X_ADDRESS, VL53L1X_IDENTIFICATION_REVISION);
Serial.print("Revision ID: ");
Serial.println(revision_id, HEX);
// Combine model and revision for complete ID (optional)
uint16_t sensor_id = (revision_id << 8 | model_id;
Serial.print("Sensor ID: 0x");
Serial.println(sensor_id, HEX);
}
uint8_t readRegister(uint8_t address, uint8_t reg) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(address, 1);
if (Wire.available() == 1) {
return Wire.read();
} else {
Serial.println("Failed to read register!");
return 0;
}
}
void loop() {
}
