ESP32-S3 QTPY not working with TOF Distance sensor VL53L4CD

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
tylersuard
 
Posts: 21
Joined: Sun Jun 03, 2018 2:45 pm

ESP32-S3 QTPY not working with TOF Distance sensor VL53L4CD

Post by tylersuard »

Hello. I can't get my TOF laser sensor to work with my ESP32-S3 QTPY, even though both use STEMMA connectors.

When I try using the CircuitPython code, I get an error saying the wrong device is found. When I try using the Arduino code, it won't work at all and instead turns the QTPY into a flash drive. Here is the code I am currently using:

Code: Select all

#include <Arduino.h>
#include <Wire.h>
#include <vl53l4cd_class.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>

#define DEV_I2C Wire
#define SerialPort Serial

#ifndef LED_BUILTIN
  #define LED_BUILTIN 13
#endif
#define LedPin LED_BUILTIN

// Components.
VL53L4CD sensor_vl53l4cd_sat(&DEV_I2C, A1);

/* Setup ---------------------------------------------------------------------*/

void setup()
{
  // Led.
  pinMode(LedPin, OUTPUT);

  // Initialize serial for output.
  SerialPort.begin(115200);
  SerialPort.println("Starting...");

  // Initialize I2C bus.
  DEV_I2C.begin();

  // Configure VL53L4CD satellite component.
  sensor_vl53l4cd_sat.begin();

  // Switch off VL53L4CD satellite component.
  sensor_vl53l4cd_sat.VL53L4CD_Off();

  //Initialize VL53L4CD satellite component.
  sensor_vl53l4cd_sat.InitSensor();

  // Program the highest possible TimingBudget, without enabling the
  // low power mode. This should give the best accuracy
  sensor_vl53l4cd_sat.VL53L4CD_SetRangeTiming(200, 0);

  // Start Measurements
  sensor_vl53l4cd_sat.VL53L4CD_StartRanging();
}

void loop()
{
  uint8_t NewDataReady = 0;
  VL53L4CD_Result_t results;
  uint8_t status;
  char report[64];

  do {
    status = sensor_vl53l4cd_sat.VL53L4CD_CheckForDataReady(&NewDataReady);
  } while (!NewDataReady);

  //Led on
  digitalWrite(LedPin, HIGH);

  if ((!status) && (NewDataReady != 0)) {
    // (Mandatory) Clear HW interrupt to restart measurements
    sensor_vl53l4cd_sat.VL53L4CD_ClearInterrupt();

    // Read measured distance. RangeStatus = 0 means valid data
    sensor_vl53l4cd_sat.VL53L4CD_GetResult(&results);
    snprintf(report, sizeof(report), "Status = %3u, Distance = %5u mm, Signal = %6u kcps/spad\r\n",
             results.range_status,
             results.distance_mm,
             results.signal_per_spad_kcps);
    SerialPort.print(report);
  }

  //Led off
  digitalWrite(LedPin, LOW);
}
And here is a picture of my setup:
IMG_3175.jpeg
IMG_3175.jpeg (678.6 KiB) Viewed 148 times
Last edited by adafruit_support_carter on Tue May 30, 2023 5:33 pm, edited 1 time in total.
Reason: added [code] tags

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

Re: ESP32-S3 QTPY not working with TOF Distance sensor VL53L4CD

Post by adafruit_support_carter »

Change this line:

Code: Select all

#define DEV_I2C Wire
to:

Code: Select all

#define DEV_I2C Wire1
The STEMMA QT ends up being Wire1 in Arduino:
https://learn.adafruit.com/adafruit-qt- ... or-3119704

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

Return to “Other Products from Adafruit”