VL53L4CX range issues

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dwilliss
 
Posts: 24
Joined: Fri Oct 31, 2014 7:26 pm

VL53L4CX range issues

Post by dwilliss »

The VL53L4CX claims to have a range up to 6000mm, but I can't get it to give me any valid readings more than about 2500mm.
By "valid" I mean a reading with a RangeStatus of 0.

I've called

Code: Select all

sensor.VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG)
which helped a bit. Before that I could only get about 2200mm.

I also tried playing around with

Code: Select all

L53L4CX_SetMeasurementTimingBudgetMicroSeconds
and

Code: Select all

VL53L4CX_PerformXTalkCalibration
with no noticeable change.

Any suggestions?

User avatar
tepalia02
 
Posts: 104
Joined: Sun Apr 24, 2022 6:53 am

Re: VL53L4CX range issues

Post by tepalia02 »

Hi, are you giving 2.8V to the sensor?

User avatar
dwilliss
 
Posts: 24
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

Post by dwilliss »

It's on the Adafruit breakout board which handles all that.
I'm just using the STEMMA QT connector to connect it to a QtPy ESP32-S2.

I did add an additional wire between the GPIO pin on the breakout and one of the GPIOs of the QtPy.
Without that, the call to VL53L4CX_GetMeasurementDataReady always returned 0
(something not mentioned in the guide, by the way)

Oh, and I did remember to remove the protective film.

User avatar
adafruit_support_carter
 
Posts: 29177
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

Post by adafruit_support_carter »

Was the extra wire for the XSHUT pin?

What code are you running? It may be something as simple as setting the correct mode for the sensor to get the desired range.

User avatar
dwilliss
 
Posts: 24
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

Post by dwilliss »

No, it's the GPIO pin on the breakout board.
According the the documentation for the VL53L4CX, the XSHUT is used for initialization and didn't seem necessary.

Here's my initialization code...

Code: Select all

  VL53L4CX *sensor;  // Actually allocate this in setup()

  // this is in setup()
  // Initialize I2C bus.
  DEV_I2C.setPins(SDA1, SCL1);
  DEV_I2C.begin();

  pinMode(A2, INPUT_PULLUP);
  sensor = new VL53L4CX(&DEV_I2C, A2);
  sensor->begin();
  sensor->VL53L4CX_Off();
  // I've tried all settings for this
  sensor->VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG);

  // Not sure why this is 0x12, but its what the example code had and that worked
  sensor->InitSensor(0x12);
  // I've tried playing with this, but the documentation doesn't really say why you'd want to change it.
  // I ended up leaving it commented out.
  // sensor->VL53L4CX_SetMeasurementTimingBudgetMicroSeconds(66666);

  sensor->VL53L4CX_StartMeasurement();
  sensor->VL53L4CX_PerformXTalkCalibration();
in loop()

Code: Select all

  uint8_t newDataReady = 0;
  sensor->VL53L4CX_GetMeasurementDataReady(&newDataReady);
  if (newDataReady) {
     VL53L4CX_MultiRangingData_t multiRangingData;
     float mr = 99999;  // I had to change this for the post because my actual variable name is apparently a banned spam word?
     for (int j = 0; j < multiRangingData.NumberOfObjectsFound; j++) {
        VL53L4CX_TargetRangeData_t *target = &multiRangingData.RangeData[j];
        if (target->RangeStatus == 0) {
           float range = target->RangeMilliMeter;
           if (range < mr) mr = range;
        }
     }
  sensor->VL53L4CX_ClearInterruptAndStartMeasurement();
  Serial.println(mr);
  }

Now, I know what you're going to say. It returns multiple values and I keep the minimum valid value.
But in reality, there's never more than one valid value. The others all have non-zero RangeStatus.

User avatar
adafruit_support_carter
 
Posts: 29177
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

Post by adafruit_support_carter »

Please post a photo of your setup showing how everything is connected. This behavior seems very odd:
I did add an additional wire between the GPIO pin on the breakout and one of the GPIOs of the QtPy.
Without that, the call to VL53L4CX_GetMeasurementDataReady always returned 0
It does not appear you are using the interrupt output. So not sure why this was needed. The basic example should work without needing to tie into that pin:
https://github.com/stm32duino/VL53L4CX/ ... oWorld.ino

If you actually did want to use interrupts, you'd code more like this example:
https://github.com/stm32duino/VL53L4CX/ ... errupt.ino

User avatar
dwilliss
 
Posts: 24
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

Post by dwilliss »

The interrupt example code shows constructing the object with A1 as the 2nd parameter in the constructor.
It then sets up an interrupt on A2.
Given that example, should A1 be connected to XSHUT or GPIO? And which pin should A2 be connected to?
I couldn't find anything in either the Adafruit guide or the documentation for the VL53L4CX itself.

I assumed (perhaps incorrectly) that the one in the constructor was the "GPIO" on the breakout, so I connected that pin to GPIO.
And this seems to work.

I'm using the sensor to sense my car in my garage and control some neopixels to show how far the car is from the back wall, flashing red when I get to where I want to stop.

The only issue I have is that I don't get the expected range. After about 2000 to 2500mm, I just don't get any valid results.
Actually, that's not entirely true. I have discovered that if I pull in at night and turn off my headlights, I get pretty long ranges. If the headlights are on, it messes it up. During the day, it messes up past about 2500mm even with the door closed (high ambient light due to windows). So I'm thinking light is effecting it - which kind of makes sense given that the thing is basically a low-powered laser. I'm going to try putting some kind of shade around it to block ambient light and see if that helps.

User avatar
adafruit_support_carter
 
Posts: 29177
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

Post by adafruit_support_carter »

The parameter in the constructor is XSHUT:
https://github.com/stm32duino/VL53L4CX/ ... lass.h#L70

So for the interrupt example:
A1 -> XSHUT
A2 -> GPIO

If interrupts are enabled and configured, the interrupt condition is indicated on the GPIO pin. It's up to you to tie into that pin - like A2 is done in the example. It doesn't need to be A2.

XSHUT simply disables / enables the sensor - like power on / power off. It's useful for resetting to a known state. You'd connect that to a digital out on your controller. That's what A1 is in the example, but it could be any other available pin.

In should be OK to leave off XSHUT and then just power cycle the setup. But if you are soft resetting things, so that the VL53L4CX does *not* get power cycled, then using XSHUT can help - since it will enforce a power cycle to a known state.

In terms of not getting data beyond a certain distance - it may take some testing and iterating. Checkout the datasheet:
https://www.st.com/resource/en/datasheet/vl53l4cx.pdf
It has some information about the field of view, the affects of different lighting conditions, as well as target reflectance:
table.jpg
table.jpg (49.7 KiB) Viewed 105 times

User avatar
dwilliss
 
Posts: 24
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

Post by dwilliss »

OK, so the lighting conditions and the color of my car are causing lower ranges.
That makes sense then. Thanks

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”