Closed ash73 closed 6 years ago
Not easy as is, I guess. Fortunately, Pololu has already ported this ST library to arduino. See his VL53L1X library for Arduino and implementation of ST's VL53L1X API for Arduino.
Yes I tried that library. It works fine on a UNO but on my ESP32 I get error -13 "error control interface" when it calls VL53L1_GetRangingMeasurementData in the loop. I think it may be a I2C problem.
Although I'm not sure about UNO I2C, some pointers say that it has on-board pull-up resistors. ESP32 devkit has no on-board I2C pull-up and the ESP32 on-chip pull-up resistors are too weak for VL53L1X. I've experienced many failures with no external pull-up. With 3k pull-up resistors, those errors went away.
Thanks for the tip, I tried a few different resistors but I can't get it to work with or without pullups. The SparkFun library works ok (but doesn't have AoI functionality) so I think it's software. I raised an issue with them but no response so far.
I've updated arduino-esp32 and got -13 error on M5Stack. Looks esp32 Wire.requestFrom returns 0 unexpectedly when the 2nd argument > 1. The workaround below works for me. Hope this helps.
diff --git a/vl53l1x-st-api/vl53l1_platform.cpp b/vl53l1x-st-api/vl53l1_platform.cpp
index f636cde..4df58bd 100644
--- a/vl53l1x-st-api/vl53l1_platform.cpp
+++ b/vl53l1x-st-api/vl53l1_platform.cpp
@@ -152,7 +152,7 @@ VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, ui
while (count > 0)
{
- uint8_t reading = Wire.requestFrom(Dev->I2cDevAddr >> 1, count);
+ uint8_t reading = Wire.requestFrom(Dev->I2cDevAddr >> 1, 1);
if (reading == 0) { return VL53L1_ERROR_CONTROL_INTERFACE; }
count -= reading;
That's brilliant thank you so much! Works just fine.
One more question if I may - do you know how to set the AoI via the API? I need to reduce the field of view to the minimum setting if possible, for my application.
I've called VL53L1_SetUserROI(Dev, &Roi) just before VL53L1_StartMeasurement/VL53L1_ClearInterruptAndStartMeasurement:
diff --git a/vl53l1x-st-api/vl53l1x-st-api.ino b/vl53l1x-st-api/vl53l1x-st-api.ino
index 23d268c..75b05ce 100644
--- a/vl53l1x-st-api/vl53l1x-st-api.ino
+++ b/vl53l1x-st-api/vl53l1x-st-api.ino
@@ -78,6 +78,12 @@ void setup()
status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_LONG);
status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 50000);
status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 50); // reduced to 50 ms from 500 ms in ST example
+ VL53L1_UserRoi_t Roi;
+ Roi.TopLeftX = 0;
+ Roi.TopLeftY = 3;
+ Roi.BotRightX = 3;
+ Roi.BotRightY = 0;
+ status = VL53L1_SetUserROI(Dev, &Roi);
status = VL53L1_StartMeasurement(Dev);
if(status)
@@ -105,6 +111,12 @@ void loop()
Serial.print(F(","));
Serial.println(RangingData.AmbientRateRtnMegaCps/65336.0);
}
+ VL53L1_UserRoi_t Roi;
+ Roi.TopLeftX = 0;
+ Roi.TopLeftY = 7;
+ Roi.BotRightX = 7;
+ Roi.BotRightY = 0;
+ status = VL53L1_SetUserROI(Dev, &Roi);
status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
}
else
The above is a test for the dynamic change of AOI. Of course, if only the fixed AOI is needed, the 2nd VL53L1_SetUserROI call isn't necessary. According to ST's API specification, minimal AOI size is 4x4 spads and 0 <= TopLeftX/Y and BotRightX/Y <= 15.
Just wanted to say a big thank you to @kazkojima, everything is working ok now! I spent a lot of time on this so I'm very happy with the result.
Hi, would it be possible to build this in the Arduino IDE using the ESP32 dev module board?