2024-10-31 05:45 AM
When i measure my distance in 4x4 i don't have any issues at all. But I need to change it to 8x8 for my project.
To my knowledge you only need to change the resolution with vl53l5cx_set_resolution() to 8x8 and adjust the frequency accordingly. I have checked if my sensor is measuring with my webcam and it is a solid red light so not blinking or anything. And when i check the output it gives me this:
Initialized
data not ready??
data not ready??
data not ready??
data not ready??
data not ready??
data not ready??
data not ready??
data not ready??
data not ready??
Status ranging: 1
Error retrieving ranging data on device 0.
======== Device 0 ========
23, 33, 28, 20, 17, 14, 12, 6,
24, 33, 701, 26, 19, 15, 11, 10,
21, 31, 32, 25, 21, 17, 13, 12,
23, 31, 34, 30, 24, 18, 15, 13,
828, 27, 33, 33, 0, 22, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
Braking
Error while checking for data ready on device 0.
data not ready??
Error while checking for data ready on device 0.
data not ready??
Error while checking for data ready on device 0.
The data not ready is just waiting till it has measured but then i get an error from the vl53l5cx_get_ranging_data() for some reason and after my sensor is obviously done till restart. Does anyone know what I'm doing wrong?
This is the relevant part of my code:
for (int dev = 0; dev < NUMDEVICES-1; dev++) { // Loop through each device
// Power on each sensor separately by setting it's LPN pin high
HAL_GPIO_WritePin(VL53L5CXLpnPorts[dev], VL53L5CXLpnPins[dev], GPIO_PIN_SET);
HAL_Delay(15); // Allow time for the sensor to stabilize
while (true) {
status = vl53l5cx_check_data_ready(&devs[dev], &dataIsReady);
if (status != VL53L5CX_STATUS_OK) {
cout << "Error while checking for data ready on device " << dev << "." << endline;
}
if (dataIsReady) {
/* Retrieve the data */
status = vl53l5cx_get_ranging_data(&devs[dev], &result);
cout << "Status ranging: " << status << endline;
if (status != VL53L5CX_STATUS_OK) {
cout << "Error retrieving ranging data on device " << dev << "." << endline;
}
for (uint8_t index = 0; index < resolution; index++) {
distanceMap[index] = result.distance_mm[index];
}
// Power off each sensor separately by setting it's LPN pin low after measuring
HAL_GPIO_WritePin(VL53L5CXLpnPorts[dev], VL53L5CXLpnPins[dev], GPIO_PIN_RESET);
HAL_Delay(15);
break; // Exit the loop for this sensor once the measurement is done
} else {
cout << "data not ready??" << endline;
}
HAL_Delay(5);
}
std::tuple<uint8_t, uint8_t> devPriority = newTuple(dev, 1);
vl53l5xLogic(distanceMap, devPriority);
}
return CONTINUE;
}
Solved! Go to Solution.
2024-11-02 08:01 AM
I solved it. By putting it in 8x8 it has more data to transmit of course, and that data was not transmitted fast enough or something? When i set my i2c to fast mode(400KHz) instead of normal speed(100KHz) it started working!
2024-10-31 05:47 AM
1 thing to add: The last 3 rows always stay 0 even when they shouldn't be. So i guess the measurement just breaks down after a certain amount of values or something?
2024-10-31 08:02 AM
I see something...
When you have multiple sensors - they all boot up at the same I2C address. 0x29 (Write address 0x52, read address 0x53).
To solve this boot up one device as in:
// Power on each sensor separately by setting it's LPN pin high
HAL_GPIO_WritePin(VL53L5CXLpnPorts[dev], VL53L5CXLpnPins[dev], GPIO_PIN_SET);
HAL_Delay(15); // Allow time for the sensor to stabilize
But the issue the Address Change command and give that sensor a different address.
then update that address in your dev structure.
Of course you are going to need several dev structs - one for each sensor. I'd suggest an array of struct's.
Next, is I don't actually see the start command. Need one of those just after the init.
Perhaps you just left that bit out when you posted the relevant bits?
You also need to check for a valid range for each zone as in:
For each zone
IF the number of targets is >0 AND the target_status is 5, 6 or 9 THEN you have a valid target.
Need that check.
- john
2024-10-31 08:21 AM
This is my innit that works when changing only the resolution right now:
#define NUMDEVICES 2//6
/* Define a configuration for every device you connect*/
VL53L5CX_Configuration devs[NUMDEVICES];
/* Define a 7-bit address for each tof sensor */
const uint8_t deviceAddresses[NUMDEVICES] = {0x54, 0x55};
GPIO_TypeDef* VL53L5CXLpnPorts[NUMDEVICES] = { // will be gone with extender
VL53L5CXLpn0_GPIO_Port,
VL53L5CXLpn1_GPIO_Port
};
uint16_t VL53L5CXLpnPins[NUMDEVICES] = { // will be gone with extender
VL53L5CXLpn0_Pin,
VL53L5CXLpn1_Pin
};
/* statuses of the sensor for error tracking */
uint8_t status, isAlive, dataIsReady;
/* The resolution used can be chosen between 4x4 and 8x8. */
const uint8_t resolution = VL53L5CX_RESOLUTION_4X4;
void initializeVL53L5X() {
for (int i = 0; i < NUMDEVICES; i++) { // Assume NUMDEVICES is defined as the number of devices
// Power on the sensor by setting the LPN pin high
HAL_GPIO_WritePin(VL53L5CXLpnPorts[i], VL53L5CXLpnPins[i], GPIO_PIN_SET);
HAL_Delay(15); // Allow time for the sensor to stabilize
devs[i].platform.address = VL53L5CX_DEFAULT_I2C_ADDRESS;
status = vl53l5cx_is_alive(&devs[i], &isAlive);
if (status != VL53L5CX_STATUS_OK || !isAlive) {
cout << status << endline;
cout << "sensor not alive on device " << i << "." << endline;
Error_Handler();
} else {
cout << "sensor is alive on device " << i << endline;
}
status = vl53l5cx_init(&devs[i]);
if (status != VL53L5CX_STATUS_OK) {
cout << "Failed to initialize VL53L5CX on device " << i << ", status: " << status << endline;
Error_Handler();
} else {
cout << "VL53L5CX initialized successfully on device " << i << endline;
}
status = vl53l5cx_set_i2c_address(&devs[i], deviceAddresses[i]);
if (status != VL53L5CX_STATUS_OK) {
cout << "Failed to set I2C address on device " << i << ", status: " << status << endline;
Error_Handler();
} else {
cout << "I2C address set to " << deviceAddresses[i] << " for device " << i << endline;
}
status = vl53l5cx_set_resolution(&devs[i], resolution);
status = vl53l5cx_set_ranging_frequency_hz(&devs[i], 15);
status = vl53l5cx_start_ranging(&devs[i]);
if (status) {
cout << "Start Ranging Failed on device " << i << endline;
}
// Power off the sensor by setting the LPN pin low after initialization
HAL_GPIO_WritePin(VL53L5CXLpnPorts[i], VL53L5CXLpnPins[i], GPIO_PIN_RESET);
HAL_Delay(15); // Allow time for the sensor to stabilize
}
}
I only don't understand what you mean with checking zones for targets? For now i just want to print the values, but as seen in my original post, it stops ranging with that error just past halfway the measurement.
2024-10-31 08:32 AM
A common I2C mistake. Not your fault. It's been an issue for nearly 25 years.
/* Define a 7-bit address for each tof sensor */
const uint8_t deviceAddresses[NUMDEVICES] = {0x54, 0x55};
The I2C has a base address (0x29) and one shifts it left one bit to get the write address (0x52) and then adds 1 to get the read address (0x53).
And you are actually defining the 8-bit address.
So to correctly create multiple I2C addresses they must be even! The odds are the read addresses.
In your code, the 0x55 became 0x54 by the time it was sent to the sensor.
I'm guessing your 4x4 worked simply because the timing was shorter and the 2 sensors didn't step on each other.
-john
2024-10-31 10:00 AM
Thanks for the quick replies! But the issue still stands, although something seems to have changed.
I2C address set to 84 for device 0
sensor is alive on device 1
I2C address set to 86 for device 1
Initialized
Status ranging: 3
Error retrieving ranging data on device 0.
======== Device 0 ========
1297, 1270, 1234, 1224, 1169, 1030, 1081, 1085,
1198, 1257, 1265, 1269, 1165, 1092, 970, 1061,
1287, 1254, 1331, 1221, 1128, 1072, 965, 989,
1162, 1195, 1422, 1117, 1144, 1056, 999, 887,
995, 1110, 1108, 1039, 0, 1046, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
Error while checking for data ready on device 1.
data not ready yet
Error while checking for data ready on device 1.
data not ready yet
As you can see I still don't get all the data but it doesn't need to wait for data ready so it seems faster, but it still stops after measuring just once. I now only changed the addresses to this: {0x54, 0x56}. That error 3 that it returns from the vl53l5cx_get_ranging_data() still seems to be present.
2024-11-02 08:01 AM
I solved it. By putting it in 8x8 it has more data to transmit of course, and that data was not transmitted fast enough or something? When i set my i2c to fast mode(400KHz) instead of normal speed(100KHz) it started working!