I got a VL53L4CX time-of-flight sensor and connected it to a QtPy ESP32-S2
Using Circuit Python, I can get results that seem accurate-ish at least up to about 55cm
But if I point it at the ceiling or the wall it reads 0 or some other small numbers (all less than 2cm)
This unit is supposed to be good for up to 6m (which would be 6000mm).
My ceiling is less than 2m away from the desk.
Is there a calibration step that I'm missing?
VL53L4CX on Qt Py ESP32-S2
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- freddyboomboom
- Posts: 267
- Joined: Wed Feb 16, 2022 7:55 pm
Re: VL53L4CX on Qt Py ESP32-S2
Possibly.
What library are you using to communicate with the VL53L4CX?
The Learn Guide for that breakout only shows it working with Arduino.
What library are you using to communicate with the VL53L4CX?
The Learn Guide for that breakout only shows it working with Arduino.
- dwilliss
- Posts: 24
- Joined: Fri Oct 31, 2014 7:26 pm
Re: VL53L4CX on Qt Py ESP32-S2
I'm using adafruit_vl53l4cd, which is the closest I could find.
I've used Arduino in past projects, so if there's no Python support, I could probably try that.
I wanted to try Circuit Python though - something new to play with :)
I've used Arduino in past projects, so if there's no Python support, I could probably try that.
I wanted to try Circuit Python though - something new to play with :)
- freddyboomboom
- Posts: 267
- Joined: Wed Feb 16, 2022 7:55 pm
Re: VL53L4CX on Qt Py ESP32-S2
You're using a library for a different TOF sensor, that tops out at 1.3 meters.
- dwilliss
- Posts: 24
- Joined: Fri Oct 31, 2014 7:26 pm
Re: VL53L4CX on Qt Py ESP32-S2
OK, that makes sense. They don't seem to have one for this specific sensor yet.
I'll either wait a few weeks to see if they get one or do this one in Arduino instead.
I'll either wait a few weeks to see if they get one or do this one in Arduino instead.
- dwilliss
- Posts: 24
- Joined: Fri Oct 31, 2014 7:26 pm
Re: VL53L4CX on Qt Py ESP32-S2
I tried this using Arduino IDE and had it somewhat working.
I had to jump through a couple hoops to make it use Wire1 since the STEMMA QT port isn't the default I2C port (seems like it should be for ease of use)
I found that the driver can return up to 4 results and you have to check the status of the results to see which one(s) are really valid.
But I had it returning values. But it was just alternating between the same 2 values (422mm and 439mm) .
Then I made a few other changes to my sketch and suddenly it stopped working
It turns out that NewDataReady is never true any more. I thought maybe I accidentally fried something, but I have 2 QT Pys and 2 VL53L4CXs and no combination of them work. I also tried putting a temperature/humidity sensor on the chain and it works fine.
Here's the whole sketch as it exists now...
I had to jump through a couple hoops to make it use Wire1 since the STEMMA QT port isn't the default I2C port (seems like it should be for ease of use)
I found that the driver can return up to 4 results and you have to check the status of the results to see which one(s) are really valid.
But I had it returning values. But it was just alternating between the same 2 values (422mm and 439mm) .
Then I made a few other changes to my sketch and suddenly it stopped working
Code: Select all
do {
status = sensor->VL53L4CX_GetMeasurementDataReady(&NewDataReady);
} while (!NewDataReady);
Here's the whole sketch as it exists now...
Code: Select all
/* Includes ------------------------------------------------------------------*/
#include <Arduino.h>
#include <Wire.h>
#include <vl53l4cx_class.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_AHTX0.h>
#define DEV_I2C Wire1 // Wire1 is the STEMMA QT port. Wire is the SDA/SLC pins
#define SerialPort Serial
Adafruit_NeoPixel boardLed(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
//Adafruit_NeoPixel ledStrip(60, PIN_D0, NEO_RGBW + NEO_KHZ800);
Adafruit_AHTX0 aht; // Temperature/humidity sensor
// Components.
VL53L4CX *sensor; // Actually allocate this in setup()
int startError, initError;
/* Setup ---------------------------------------------------------------------*/
void setup()
{
// Initialize serial for output.
Serial.begin(115200);
delay(500);
Serial.println("Starting...\r\n"); // for some reason, nothing I print in setup() ever shows up
// Initialize I2C bus.
DEV_I2C.setPins(SDA1, SCL1);
DEV_I2C.begin();
aht.begin(&DEV_I2C, 0);
// Except for changing this to a pointer and allocating it in setup this is the same as
// the example code for the sensor. I had to allocate it AFTER configuring I2C as Wire1
// when I got it to work the first time.
sensor = new VL53L4CX(&DEV_I2C, A1);
sensor->begin();
sensor->VL53L4CX_Off();
// Commenting out for now - maybe this was a problem?
//sensor->VL53L4CX_SetDistanceMode(VL53L4CX_DISTANCEMODE_LONG);
// Not sure why this is 0x12, but its what the example code had and that worked
initError = sensor->InitSensor(0x12);
// Start Measurements
startError = sensor->VL53L4CX_StartMeasurement();
}
void loop()
{
VL53L4CX_MultiRangingData_t MultiRangingData;
VL53L4CX_MultiRangingData_t *pMultiRangingData = &MultiRangingData;
uint8_t NewDataReady = 1;
int no_of_object_found = 0, j;
char report[80];
int status;
// Debugging - report the results of a couple calls from setup since nothing I
// print there ever shows up.
snprintf(report, sizeof(report), "InitError=%d, StartError=%d ", initError, startError);
Serial.println(report);
// This temp/humidity works which proves that the I2C bus is fine.
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
Serial.println("waiting for data ready");
delay(20);
boardLed.fill(0x770000); // Set the neopixel on the board to red
boardLed.show();
do {
status = sensor->VL53L4CX_GetMeasurementDataReady(&NewDataReady);
yield();
} while (!NewDataReady);
boardLed.fill(0x007700); // Set the neopixel on the board to green (we never get here)
boardLed.show();
snprintf(report, sizeof(report), "DataReady=%d status=%d ", NewDataReady, status);
Serial.println(report);
if ((!status) && (NewDataReady != 0)) {
status = sensor->VL53L4CX_GetMultiRangingData(pMultiRangingData);
no_of_object_found = pMultiRangingData->NumberOfObjectsFound;
snprintf(report, sizeof(report), "VL53L4CX: Status=%d, Count=%d, #Objs=%1d\r\n ", status, pMultiRangingData->StreamCount, no_of_object_found);
Serial.print(report);
for (j = 0; j < no_of_object_found; j++) {
if (pMultiRangingData->RangeData[j].RangeStatus != 0) continue;
Serial.print(" ");
Serial.print("status=");
Serial.print(pMultiRangingData->RangeData[j].RangeStatus);
Serial.print(", D=");
Serial.print(pMultiRangingData->RangeData[j].RangeMilliMeter);
Serial.print("mm");
Serial.print(", Signal=");
Serial.print((float)pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65536.0);
Serial.print(" Mcps, Ambient=");
Serial.print((float)pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65536.0);
Serial.print(" Mcps\r\n");
}
Serial.println("");
if (status == 0) {
status = sensor->VL53L4CX_ClearInterruptAndStartMeasurement();
}
}
delay(500);
}
- ProtoPix
- Posts: 57
- Joined: Sun Sep 11, 2016 6:49 pm
Re: VL53L4CX on Qt Py ESP32-S2
For what it's worth, I have both the Adafruit VL53L4CD and VL53L4CX TOF sensors. They appear to be nearly the same sensor if not the same. The VL53L4CX driver works with both devices. Both devices also return Device Id of 0xEBAA.
I am sitting here with my Qt Py ESP32S2 board connected to the Adafruit VL53L4CD Time of Flight Distance Sensor, and using the stm32duino/STM32duino VL53L4CX driver, I'm seeing the following serial terminal output:
desktop to the ceiling: VL53L4CX Proximity (mm): 2013 (in): 79.25
room wall to opposite wall: VL53L4CX Proximity (mm): 3282 (in): 129.21
Which are very good values.
Are Adafruit's VL53L4[CD/CX] devices the same? The VL53L4CX datasheet indicates the device Id should be 0xEAAA, but for my Adafruit VL53L4CX device, it is the same as my VL53L4CD device.
Is it possible that the VL53L4CD sensor could have been integrated into some Adafruit VL53L4CX Time of Flight Distance devices?
I am sitting here with my Qt Py ESP32S2 board connected to the Adafruit VL53L4CD Time of Flight Distance Sensor, and using the stm32duino/STM32duino VL53L4CX driver, I'm seeing the following serial terminal output:
desktop to the ceiling: VL53L4CX Proximity (mm): 2013 (in): 79.25
room wall to opposite wall: VL53L4CX Proximity (mm): 3282 (in): 129.21
Which are very good values.
Are Adafruit's VL53L4[CD/CX] devices the same? The VL53L4CX datasheet indicates the device Id should be 0xEAAA, but for my Adafruit VL53L4CX device, it is the same as my VL53L4CD device.
Is it possible that the VL53L4CD sensor could have been integrated into some Adafruit VL53L4CX Time of Flight Distance devices?
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: VL53L4CX on Qt Py ESP32-S2
Any similarities between CD/CX would be an STM thing, not an Adafruit sensor breakout thing.
The Adafruit VL53L4CD breakouts use STM VL53L4CDs
The Adafruit VL53L4CX breakouts use STM VL53L4CXs
The Adafruit VL53L4CD breakouts use STM VL53L4CDs
The Adafruit VL53L4CX breakouts use STM VL53L4CXs
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: VL53L4CX on Qt Py ESP32-S2
that said - you must use the matching sensor. the circuitpython driver for the CD cannot be used for the CX and vice cersa
- ProtoPix
- Posts: 57
- Joined: Sun Sep 11, 2016 6:49 pm
Re: VL53L4CX on Qt Py ESP32-S2
Understood to all replies! Thanks!
Please be positive and constructive with your questions and comments.