cbroo
December 14, 2022, 5:01pm
1
Hello,
I want to measure a distance with a laser sensor from Adafruit. I have followed their tutorial in order to read the measure with my Arduino Uno (Overview | Adafruit VL53L4CD Time of Flight Distance Sensor | Adafruit Learning System ). Unfortunately it's not working for me.
I have connected the Vin to 5V, GND, SCL and SDA to the pins having the same name. I have download the library here (GitHub - stm32duino/VL53L4CD: Arduino library to support the VL53L4CD Time-of-Flight high accuracy proximity sensor ). Then I am trying to use the first example "HelloWorld". When I upload my code to the Arduino, I can see that the led from the laser sensor switch on so something is happening. Then I open the Serial Monitor and I can read "Starting..." but nothing else. I have done some testing and it appears that the code runs until the line "sensor_vl53l4cd_sat.InitSensor();". Has anyone experienced similar results? I don't know what to do as I don't have any error message. If you have a suggestion that would be very nice.
Thank you for reading me.
pylon
December 14, 2022, 6:41pm
2
That example expects the XSHUT signal of the Adafruit board to be connected to the A1 pin of the UNO, at least if you use it unchanged.
cbroo
December 15, 2022, 9:03am
3
Hi, yes sorry I forgot to mention that I have also tried to connect the A1 pin to the Xshut and the A2 to GPIO but I have the same problem
Well on a Uno it should be connected to A5 and A4 as those are the I2C lines.
SCL - I2C clock pin, connect to your microcontroller I2C clock line. There's a 10K pullup on this pin.
SDA - I2C data pin, connect to your microcontroller I2C data line. There's a 10K pullup on this pin.
Can you post the actual code you are using and a schematic of how it is all connected up.
cbroo
December 15, 2022, 9:46am
5
Thanks a lot for your help !
/**
******************************************************************************
* @file VL53L4CD_Sat_HelloWorld.ino
* @author STMicroelectronics
* @version V1.0.0
* @date 29 November 2021
* @brief Arduino test application for the STMicrolectronics VL53L4CD
* proximity sensor satellite based on FlightSense.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2021 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/*
* To use this sketch you need to connect the VL53L4CD satellite sensor directly to the Nucleo board with wires in this way:
* pin 1 (GND) of the VL53L4CD satellite connected to GND of the Nucleo board
* pin 2 (VDD) of the VL53L4CD satellite connected to 3V3 pin of the Nucleo board
* pin 3 (SCL) of the VL53L4CD satellite connected to pin D15 (SCL) of the Nucleo board
* pin 4 (SDA) of the VL53L4CD satellite connected to pin D14 (SDA) of the Nucleo board
* pin 5 (GPIO1) of the VL53L4CD satellite connected to pin A2 of the Nucleo board
* pin 6 (XSHUT) of the VL53L4CD satellite connected to pin A1 of the Nucleo board
*/
/* Includes ------------------------------------------------------------------*/
#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();
SerialPort.println("1...");
//Initialize VL53L4CD satellite component.
sensor_vl53l4cd_sat.InitSensor();
SerialPort.println("2...");
// 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);
}
On the Serial I can read "Starting..." then "1..." but the "2..." doesn't appear.
Previously I was directly making the connections according to the tutorial schematic:
cbroo
December 15, 2022, 12:11pm
6
I just tried to connect A5 to SCL and A4 to SDA + XSHUT to A1 but unfortunalty it didn't change anything
In the code in the following line, maybe I should change something to establish the connection with A5 and A4 as you re suggesting ?
VL53L4CD sensor_vl53l4cd_sat(&DEV_I2C, A1);
cbroo
December 15, 2022, 12:30pm
7
It's working !
The problem was much simpler. The example actually works on an Arduino Uno board with the connections stipulated in the tutorial. My problem was that I'm a terrible solderer and I ended up with some tin between two components.
So sorry for this. But thanks a lot for your help, you are amazing !
cbroo:
It's working !
Well done
On that Arduino clone you have then there is the same signal as A4 and A5 on those pins at the other side of the board, so it would not have mattered which pair of connectors you chose.
cbroo
December 15, 2022, 2:45pm
9
ok thanks for the info
But I guess than if I want to use A4 and A5 I need to change this command right ?
VL53L4CD sensor_vl53l4cd_sat(&DEV_I2C, A1);
I did try to put my SCL and SDA on A4 and 5 but the laser sensor doesn't work if I do that. This leads me to the conclusion that it is possible to deactivate pins A1/4/5 and that the sensor will still work. That would be great as I would like to use 4 others sensors. I tried to delete A1 in the previous command line but this one need 2 args.
No they are the same pins from the chip just brought out to two places on the printed circuit pin.
In the way you have three ground connectors, but they are all electrically connected to the same points on the chip.
system
Closed
June 13, 2023, 3:51pm
11
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.