I think the VL53L4CD driver will work with the VL53L4CX device. Here's some code fragments I use for both devices (altered in this editor so they may need modifying in your environment if planning any testing):
- Code: Select all | TOGGLE FULL SIZE
bool VL53L4CDCheck(TwoWire *wire)
{
// Initialize I2C bus ( Wire or Wire1 depending on bus device is connected )
wire->begin();
// Configure VL53L4CD satellite component.
VL53L4CD vl53l4cd = VL53L4CD(wire, XSHUT_PIN);
vl53l4cd.begin();
// Switch off VL53L4CD satellite component.
vl53l4cd.VL53L4CD_Off();
//Initialize VL53L4CD satellite component.
VL53L4CD_ERROR status = vl53l4cd.InitSensor();
if (status == VL53L4CD_ERROR_NONE)
{
// Expected ID: 0xEBAA
vl53l4cd.VL53L4CD_GetSensorId(&VL53L4CD_ID);
Serial.print("VL53L4CD Sensor Id: 0x"); Serial.println(VL53L4CD_ID,HEX);
vl53l4cd.end();
}
wire->end();
return (status == VL53L4CD_ERROR_NONE);
//-----------------------------------------------------------------------------
bool VL53L4CXCheck(TwoWire *wire)
{
// Initialize I2C bus.
wire->begin();
// Configure VL53L4CX satellite component.
vl53l4cx.setI2cDevice(wire); // dependent on added VL53L4CX() constructor & functions to vl53l4cx_class.h
vl53l4cx.setXShutPin(XSHUT_PIN); // dependent on added VL53L4CX() constructor & functions to vl53l4cx_class.h
vl53l4cx.begin();
// Switch off VL53L4CX satellite component.
vl53l4cx.VL53L4CX_Off();
//Initialize VL53L4CX satellite component.
// dev.address is the actual I2c physical address.
// Shift the I2c address left to the expected I2c address
// expected by the driver which internally, shifts it right
// to set it to the actual physical I2c address.
VL53L4CX_Error status = vl53l4cx.InitSensor((dev.address << 1));
if (status == VL53L4CX_ERROR_NONE)
{
uint16_t sensorId;
vl53l4cx.VL53L4CX_GetSensorId(&sensorId); // New function add to driver via GitHub PR
Serial.print(" VL53L4CX SensorId: 0x");
Serial.println(sensorId, HEX);
// Expected Device Type: 0xAA expected for VL53L4CX
vl53l4cx.VL53L4CX_GetDeviceInfo(&VL53L4CX_DEV_INFO);
uint8_t deviceType = VL53L4CX_DEV_INFO.ProductType;
Serial.print(" Device Type: "); Serial.println(deviceType, HEX);
Serial.print(" Product Revision: ");
Serial.print(VL53L4CX_DEV_INFO.ProductRevisionMajor);
Serial.print(".");
Serial.println(VL53L4CX_DEV_INFO.ProductRevisionMinor);
VL53L4CX_Version_t version;
vl53l4cx.VL53L4CX_GetVersion(&version);
Serial.print(" Product version: ");
Serial.print(version.build); Serial.print(" ");
Serial.print(version.major); Serial.print(" ");
Serial.print(version.minor); Serial.print(" ");
Serial.println(version.revision); Serial.print(" ");
vl53l4cx.end();
}
wire->end();
return (status == VL53L4CX_ERROR_NONE);
}
}
I also submitted a couple of pull requests on GitHub at stm32duino/VL53L4CX, both have been merged, but only the first has been included in their latest library (version 1.1.0) so far. The latest PR included new function VL53L4CX_GetSensorId, comparable VL53L4CD_GetSensorId.
If you are doing any testing with the VL53L4CX driver, you will need to fetch the latest code from GitHub to get the GetSensorId function.
I originally had assumed the device Id for VL53L4CX was 0xEAAA per an earlier datasheet but the latest datasheet does document the device Id as the same as the VL53L4CD device. Only the firmware appears to be different per a PR reviewer but I don't see anything I recognize in the API that returns the firmware version for either device.
Not sure all that went into the firmware changes but the VL53L4CX driver works for
my VL53L4CD device giving it expanded range.