2025-10-23 2:00 PM - last edited on 2025-10-23 2:10 PM by Peter BENSCH
STMicroelectronics support,
I am testing a VL6180X laser sensor device for use in autonomous robotics.
I currently get good distance measurements using an Arduino sketch but can't use that platform in my final product.
Instead I'm using a pic18f46k22 microcontroller but the measured value of the distance at register 0X62 always reads zero.
The device is configured exactly as shown in the Arduino_VL6180X.cpp file and I can successfully read the VL6180X slave address at register 0x212. All voltages for the sensor are 3.3.
I have used a pic and I2C with other devices and I'm getting all the acknowledgements with the VL6180X.
My code for reading the measurement is:
int readDistance(void)
{
int distance = 0;
I2C_Master_Start();
I2C_Master_Write(0x29 << 1); // TOF050C I²C address write
I2C_Master_Write(0x18); // VL6180X_REG_SYSRANGE_START
I2C_Master_Write(0x01); // start a distance measurement
__delay_us(100); // wait for measurement to complete
I2C_Master_RepeatedStart();
I2C_Master_Write(0x29 << 1); // TOF050C I²C address write
I2C_Master_Write(0x62); // register to read distance
I2C_Master_RepeatedStart();
I2C_Master_Write((0x29 << 1) | 1); // TOF050C I²C address read
distance = I2C_Read_Byte(1); // Read the measured distance
I2C_Master_Stop();
return (distance);
} // end unsigned int readDistance(void)
I must be missing something.
Jerry Donaldson
2025-10-23 2:18 PM
Welcome @jerryD, to the community!
I am very sorry to inform you that the device VL6180X has already been discontinued. Since all documentation has been destroyed (except some remnants at the website) no one at STMicroekectronics can help you anymore. However, perhaps there is a community user who still has documentation and can help you.
Good luck!
Regards
/Peter