0

VL53L4CX range issues
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

VL53L4CX range issues

by dwilliss on Fri May 27, 2022 5:41 pm

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 | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
L53L4CX_SetMeasurementTimingBudgetMicroSeconds
and
Code: Select all | TOGGLE FULL SIZE
VL53L4CX_PerformXTalkCalibration
with no noticeable change.

Any suggestions?

dwilliss
 
Posts: 19
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

by tepalia02 on Sat May 28, 2022 7:57 am

Hi, are you giving 2.8V to the sensor?

tepalia02
 
Posts: 100
Joined: Sun Apr 24, 2022 6:53 am

Re: VL53L4CX range issues

by dwilliss on Sat May 28, 2022 9:40 am

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.

dwilliss
 
Posts: 19
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

by adafruit_support_carter on Tue May 31, 2022 7:04 pm

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.

adafruit_support_carter
 
Posts: 23681
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

by dwilliss on Wed Jun 01, 2022 12:25 am

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 | TOGGLE FULL SIZE
  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 | TOGGLE FULL SIZE
  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.

dwilliss
 
Posts: 19
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

by adafruit_support_carter on Wed Jun 01, 2022 12:30 pm

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

adafruit_support_carter
 
Posts: 23681
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

by dwilliss on Wed Jun 01, 2022 5:43 pm

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.

dwilliss
 
Posts: 19
Joined: Fri Oct 31, 2014 7:26 pm

Re: VL53L4CX range issues

by adafruit_support_carter on Thu Jun 02, 2022 3:13 pm

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 33 times

adafruit_support_carter
 
Posts: 23681
Joined: Tue Nov 29, 2016 2:45 pm

Re: VL53L4CX range issues

by dwilliss on Thu Jun 02, 2022 5:55 pm

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

dwilliss
 
Posts: 19
Joined: Fri Oct 31, 2014 7:26 pm

Please be positive and constructive with your questions and comments.