Adding multiple vl53l0x sensors
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-15 7:49 AM
Hi all
I have successfully implemented a single vl53l0x sensor, but wish to add more. I found the "AN4846 Application note Using multiple VL53L0X in a single design" documentation:
Under "VL53L0X API management" it specifies:
In vl53L0x_platform.h API file set VL53L0x_SINGLE_DEVICE_DRIVER macro to 0 so that API implementation will be automatically adapted to a multi-device context.
But I cannot find anything called "VL53L0x_SINGLE_DEVICE_DRIVER" in the vl53L0x_platform.h file.
Where can I find it? Or has the files updated without the documentation being updated? If so should this step just be skipped?
Solved! Go to Solution.
- Labels:
-
Time of flight
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-17 1:52 AM
Okay, I now added the VL53L0X_ResetDevice() function before each device's VL53L0X_DataInit(). The reading still doesn't change for the second sensor. Should I reset the device before each reading, or just before the DataInit?
I then added a new struct in order to save sensors in different structs. It also didn't change anything.
I added a new variable to save the distance data in separate variables rather than overwriting one. The second sensor now only gives a reading of 0. So it would seem that the data isn't being updated when VL53L0X_PerformSingleRangingMeasurement() is called.
I checked the range status for sensor 2, it also gives 0.
When I switch the sensors (through the previously done XShut method). The 2nd sensor gives a reading, but the first sensor does not.
I also tried switching the sensors off (by bringing xshut low) when not in use. But that didn't do anything either.
I added the status+= and found a value of 236 when resetting the second sensor. If I remove the reset and just use DataInit() the status = 236. The initialization, reset and address change of the first sensor gave 0 values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-17 12:59 PM
So I have established the device fails to reset. I don't know how to fix this other than physically disconnect and reconnecting the device. It then starts giving its own readings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-04 7:23 PM
I'm planning to use two arrays of three VL53L0X sensors each in a robotics application using a Teensy (Arduino-ish) microcontroller. I have one array of three sensors working already, using the technique described by John. I have a fairly detailed post, with software on my blog site at https://www.fpaynter.com/2020/06/replacing-hc-sro4-ultrasonic-sensors-with-vl53l0x-arrays/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-19 11:30 AM
I have similar situation. I want to use 2 sensors, but when they are both online(XSHUT=1) measurement data is wrong and random when I use one sensor data is OK. I add my code maybe I do something wrong...
Config:
#define sensor_qty 2 // max. 2
#define original_addr 0x52
#define sensor1_addr 0x53
#define sensor2_addr 0x54
main:
uint8_t Message[64];
uint8_t MessageLen;
VL53L0X_RangingMeasurementData_t RangingData[sensor_qty];
VL53L0X_Dev_t vl53l0x_c[sensor_qty]; // center module
VL53L0X_DEV Dev = &vl53l0x_c[0];
VL53L0X_DEV Dev1 = &vl53l0x_c[1];
//
// VL53L0X initialisation stuff
//
uint32_t refSpadCount;
uint8_t isApertureSpads;
uint8_t VhvSettings;
uint8_t PhaseCal;
uint16_t sensorMeasure[sensor_qty];
Dev->I2cHandle = &hi2c1;
Dev1->I2cHandle = &hi2c1;
Dev->I2cDevAddr = Dev1->I2cDevAddr = original_addr;
HAL_GPIO_WritePin(TOF_XSHUT1_GPIO_Port, TOF_XSHUT1_Pin, GPIO_PIN_RESET); // Disable XSHUT
HAL_GPIO_WritePin(TOF_XSHUT2_GPIO_Port, TOF_XSHUT2_Pin, GPIO_PIN_RESET); // Disable XSHUT
HAL_Delay(10);
// addr change 1st sensor
HAL_GPIO_WritePin(TOF_XSHUT1_GPIO_Port, TOF_XSHUT1_Pin, GPIO_PIN_SET); // Enable XSHUT
HAL_Delay(20);
//VL53L0X_ResetDevice(Dev);
VL53L0X_WaitDeviceBooted(Dev);
VL53L0X_DataInit( Dev );
MessageLen = sprintf((char*)Message,"Addr change 1: %i \n\r\n\r", VL53L0X_SetDeviceAddress(Dev, sensor1_addr));
HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
Dev->I2cDevAddr = sensor1_addr;
VL53L0X_WaitDeviceBooted( Dev );
//VL53L0X_DataInit( Dev );
VL53L0X_StaticInit( Dev );
VL53L0X_PerformRefCalibration(Dev, &VhvSettings, &PhaseCal);
VL53L0X_PerformRefSpadManagement(Dev, &refSpadCount, &isApertureSpads);
VL53L0X_SetDeviceMode(Dev, VL53L0X_DEVICEMODE_SINGLE_RANGING);
// Enable/Disable Sigma and Signal check
VL53L0X_SetLimitCheckEnable(Dev, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
VL53L0X_SetLimitCheckEnable(Dev, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
VL53L0X_SetLimitCheckValue(Dev, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, (FixPoint1616_t)(0.1*65536));
VL53L0X_SetLimitCheckValue(Dev, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, (FixPoint1616_t)(60*65536));
VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev, 33000);
VL53L0X_SetVcselPulsePeriod(Dev, VL53L0X_VCSEL_PERIOD_PRE_RANGE, 18);
VL53L0X_SetVcselPulsePeriod(Dev, VL53L0X_VCSEL_PERIOD_FINAL_RANGE, 14);
// addr change 2nd sensor
HAL_GPIO_WritePin(TOF_XSHUT2_GPIO_Port, TOF_XSHUT2_Pin, GPIO_PIN_SET); // Enable XSHUT
HAL_Delay(20);
//VL53L0X_ResetDevice(Dev1);
VL53L0X_WaitDeviceBooted(Dev1);
//VL53L0X_DataInit( Dev1 );
MessageLen = sprintf((char*)Message,"Addr change 2: %i \n\r\n\r", VL53L0X_SetDeviceAddress(Dev1, sensor2_addr));
HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
Dev1->I2cDevAddr = sensor2_addr;
VL53L0X_WaitDeviceBooted( Dev1 );
VL53L0X_DataInit( Dev1 );
VL53L0X_StaticInit( Dev1 );
VL53L0X_PerformRefCalibration(Dev1, &VhvSettings, &PhaseCal);
VL53L0X_PerformRefSpadManagement(Dev1, &refSpadCount, &isApertureSpads);
VL53L0X_SetDeviceMode(Dev1, VL53L0X_DEVICEMODE_SINGLE_RANGING);
// Enable/Disable Sigma and Signal check
VL53L0X_SetLimitCheckEnable(Dev1, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
VL53L0X_SetLimitCheckEnable(Dev1, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
VL53L0X_SetLimitCheckValue(Dev1, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, (FixPoint1616_t)(0.1*65536));
VL53L0X_SetLimitCheckValue(Dev1, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, (FixPoint1616_t)(60*65536));
VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev1, 33000);
VL53L0X_SetVcselPulsePeriod(Dev1, VL53L0X_VCSEL_PERIOD_PRE_RANGE, 18);
VL53L0X_SetVcselPulsePeriod(Dev1, VL53L0X_VCSEL_PERIOD_FINAL_RANGE, 14);
measure loop:
if(VL53L0X_PerformSingleRangingMeasurement(Dev, &RangingData[0]) == 0){
if(RangingData[0].RangeStatus == 0){
sensorMeasure[0]= RangingData[0].RangeMilliMeter;
}else{
//MessageLen = sprintf((char*)Message, "STATUS1: %i\n\r", RangingData.RangeStatus);
//HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
}
}else{
//MessageLen = sprintf((char*)Message, "BRAK POMIARU!\n\r");
//HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
}
if(VL53L0X_PerformSingleRangingMeasurement(Dev1, &RangingData[1]) == 0){
if(RangingData[1].RangeStatus == 0){
sensorMeasure[1]= RangingData[1].RangeMilliMeter;
}else{
//MessageLen = sprintf((char*)Message, "STATUS2: %i\n\r", RangingData.RangeStatus);
//HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
}
}else{
//MessageLen = sprintf((char*)Message, "BRAK POMIARU!\n\r");
//HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
}
MessageLen = sprintf((char*)Message, "Pomiar odleglosci: %imm %imm\n\r", sensorMeasure[0], sensorMeasure[1]);
HAL_UART_Transmit(&huart1, Message, MessageLen, 100);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-19 12:14 PM
I have been using 7ea VL53L0X in my robotics projects for quite some time with no problems after I figured out how to initialize them to unique addresses (this must be done each time in setup()). Here is a link to my blog site where you can see how it is done. You should be able to copy/paste my setup() function into your code and modify for just 2ea VL53L0X
Hope this helps,
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-19 1:22 PM
thx, but Your code is for Arduino my is written in Cube based on ST API. I assume here can be an issue...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-19 3:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-20 8:06 AM
thx, i will check based on Your advice!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-21 8:17 AM
I have another suggestion that might also help. There is a project on ST.com.:
STSW-IMG017 Embedded SoftwareImaging software2D LIDAR using multiple VL53L1X Time-of-Flight long distance ranging sensors.
This project is for the VL53L1X, but just look over the initialization section. It inits 9 sensors. It also
uses a Nucleo board, so that might help as well.
But I do have to admit that Knawa.1's code is pretty good and should get you rolling.
- john
If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-06-21 8:23 AM
Oops - I found the bug. In your code
#define original_addr 0x52
#define sensor1_addr 0x53
#define sensor2_addr 0x54
your addresses are too close together.
Each I2C device has a write address and a read address. And the read is has the LSB set.
So only use even addresss to set them. That leaves the odd addresses open for the reads.
I use 62,72,82 ... but you could use 54, 56, 58... just as easily.
If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
