Skip to content

Commit b53a27e

Browse files
committed
Add VL53L7CX driver and relative examples
1 parent a7da991 commit b53a27e

20 files changed

+26773
-1
lines changed

LICENSE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
COPYRIGHT(c) 2021 STMicroelectronics
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
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.
7+
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.
8+
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.

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# VL53L7CX
2-
Arduino library to support the VL53L7CX Time-of-Flight 8x8 multizone ranging sensor with 90 degrees FoV
2+
Arduino library to support the VL53L7CX Time-of-Flight 8x8 multizone ranging sensor with wide field view.
3+
4+
## API
5+
6+
This sensor uses I2C to communicate. And I2C instance is required to access to the sensor.
7+
The APIs provide simple distance measure and multizone detection in both polling and interrupt modes.
8+
9+
## Examples
10+
11+
The examples contained in this library are based on VL53L7CX-SATEL sensor board. You need to connect the VL53L7CX-SATEL sensor board directly to the Nucleo board with wires as explained below:
12+
- pin 1 (GND) of the VL53L7CX satellite connected to GND of the Nucleo board
13+
- pin 2 (IOVDD) of the VL53L7CX satellite connected to 3V3 pin of the Nucleo board
14+
- pin 3 (AVDD) of the VL53L7CX satellite connected to 5V pin of the Nucleo board
15+
- pin 4 (PWREN) of the VL53L7CX satellite connected to pin A5 of the Nucleo board
16+
- pin 5 (LPn) of the VL53L7CX satellite connected to pin A3 of the Nucleo board
17+
- pin 6 (SCL) of the VL53L7CX satellite connected to pin D15 (SCL) of the Nucleo board
18+
- pin 7 (SDA) of the VL53L7CX satellite connected to pin D14 (SDA) of the Nucleo board
19+
- pin 8 (I2C_RST) of the VL53L7CX satellite connected to pin A1 of the Nucleo board
20+
- pin 9 (INT) of the VL53L7CX satellite connected to pin A2 of the Nucleo board
21+
22+
There are 2 examples with the VL53L7CX library:
23+
24+
* VL53L7CX_HelloWorld: This example code is to show how to get multizone detection and proximity values of the VL53L7CX satellite sensor in polling mode.
25+
26+
* VL53L7CX_ThresholdsDetection: This example code is to show how to configure the thresholds detection of the VL53L7CX satellite sensor.
27+
28+
## Documentation
29+
30+
You can find the source files at
31+
https://github.com/stm32duino/VL53L7CX
32+
33+
The VL53L7CX datasheet is available at
34+
https://www.st.com/en/imaging-and-photonics-solutions/VL53L7CX.html
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
/**
2+
******************************************************************************
3+
* @file VL53L7CX_HelloWorld.ino
4+
* @author STMicroelectronics
5+
* @version V1.0.0
6+
* @date 16 January 2023
7+
* @brief Arduino test application for STMicroelectronics VL53L7CX
8+
* proximity sensor satellite based on FlightSense.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2021 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
/*
41+
* To use these examples you need to connect the VL53L7CX satellite sensor directly to the Nucleo board with wires as explained below:
42+
* pin 1 (GND) of the VL53L7CX satellite connected to GND of the Nucleo board
43+
* pin 2 (IOVDD) of the VL53L7CX satellite connected to 3V3 pin of the Nucleo board
44+
* pin 3 (AVDD) of the VL53L7CX satellite connected to 5V pin of the Nucleo board
45+
* pin 4 (PWREN) of the VL53L7CX satellite connected to pin A5 of the Nucleo board
46+
* pin 5 (LPn) of the VL53L7CX satellite connected to pin A3 of the Nucleo board
47+
* pin 6 (SCL) of the VL53L7CX satellite connected to pin D15 (SCL) of the Nucleo board
48+
* pin 7 (SDA) of the VL53L7CX satellite connected to pin D14 (SDA) of the Nucleo board
49+
* pin 8 (I2C_RST) of the VL53L7CX satellite connected to pin A1 of the Nucleo board
50+
* pin 9 (INT) of the VL53L7CX satellite connected to pin A2 of the Nucleo board
51+
*/
52+
53+
/* Includes ------------------------------------------------------------------*/
54+
#include <Arduino.h>
55+
#include <Wire.h>
56+
#include <vl53l7cx_class.h>
57+
58+
59+
#ifdef ARDUINO_SAM_DUE
60+
#define DEV_I2C Wire1
61+
#else
62+
#define DEV_I2C Wire
63+
#endif
64+
#define SerialPort Serial
65+
66+
#define LPN_PIN A3
67+
#define I2C_RST_PIN A1
68+
#define PWREN_PIN A5
69+
70+
void print_result(VL53L7CX_ResultsData *Result);
71+
void clear_screen(void);
72+
void handle_cmd(uint8_t cmd);
73+
void display_commands_banner(void);
74+
75+
// Components.
76+
VL53L7CX sensor_vl53l7cx_top(&DEV_I2C, LPN_PIN, I2C_RST_PIN);
77+
78+
bool EnableAmbient = false;
79+
bool EnableSignal = false;
80+
uint8_t res = VL53L7CX_RESOLUTION_4X4;
81+
char report[256];
82+
83+
/* Setup ---------------------------------------------------------------------*/
84+
void setup()
85+
{
86+
87+
// Enable PWREN pin if present
88+
if (PWREN_PIN >= 0) {
89+
pinMode(PWREN_PIN, OUTPUT);
90+
digitalWrite(PWREN_PIN, HIGH);
91+
delay(10);
92+
}
93+
94+
// Initialize serial for output.
95+
SerialPort.begin(460800);
96+
97+
// Initialize I2C bus.
98+
DEV_I2C.begin();
99+
100+
// Configure VL53L7CX component.
101+
sensor_vl53l7cx_top.begin();
102+
103+
sensor_vl53l7cx_top.init_sensor();
104+
105+
// Start Measurements
106+
sensor_vl53l7cx_top.vl53l7cx_start_ranging();
107+
}
108+
109+
void loop()
110+
{
111+
VL53L7CX_ResultsData Results;
112+
uint8_t NewDataReady = 0;
113+
uint8_t status;
114+
115+
do {
116+
status = sensor_vl53l7cx_top.vl53l7cx_check_data_ready(&NewDataReady);
117+
} while (!NewDataReady);
118+
119+
if ((!status) && (NewDataReady != 0)) {
120+
status = sensor_vl53l7cx_top.vl53l7cx_get_ranging_data(&Results);
121+
print_result(&Results);
122+
}
123+
124+
if (Serial.available()>0)
125+
{
126+
handle_cmd(Serial.read());
127+
}
128+
delay(1000);
129+
}
130+
131+
void print_result(VL53L7CX_ResultsData *Result)
132+
{
133+
int8_t i, j, k, l;
134+
uint8_t zones_per_line;
135+
uint8_t number_of_zones = res;
136+
137+
zones_per_line = (number_of_zones == 16) ? 4 : 8;
138+
139+
display_commands_banner();
140+
141+
SerialPort.print("Cell Format :\n\n");
142+
143+
for (l = 0; l < VL53L7CX_NB_TARGET_PER_ZONE; l++)
144+
{
145+
snprintf(report, sizeof(report)," \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status");
146+
SerialPort.print(report);
147+
148+
if(EnableAmbient || EnableSignal)
149+
{
150+
snprintf(report, sizeof(report)," %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
151+
SerialPort.print(report);
152+
}
153+
}
154+
155+
SerialPort.print("\n\n");
156+
157+
for (j = 0; j < number_of_zones; j += zones_per_line)
158+
{
159+
for (i = 0; i < zones_per_line; i++)
160+
SerialPort.print(" -----------------");
161+
SerialPort.print("\n");
162+
163+
for (i = 0; i < zones_per_line; i++)
164+
SerialPort.print("| ");
165+
SerialPort.print("|\n");
166+
167+
for (l = 0; l < VL53L7CX_NB_TARGET_PER_ZONE; l++)
168+
{
169+
// Print distance and status
170+
for (k = (zones_per_line - 1); k >= 0; k--)
171+
{
172+
if (Result->nb_target_detected[j+k]>0)
173+
{
174+
snprintf(report, sizeof(report),"| \033[38;5;10m%5ld\033[0m : %5ld ",
175+
(long)Result->distance_mm[(VL53L7CX_NB_TARGET_PER_ZONE * (j+k)) + l],
176+
(long)Result->target_status[(VL53L7CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
177+
SerialPort.print(report);
178+
}
179+
else
180+
{
181+
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");
182+
SerialPort.print(report);
183+
}
184+
}
185+
SerialPort.print("|\n");
186+
187+
if (EnableAmbient || EnableSignal )
188+
{
189+
// Print Signal and Ambient
190+
for (k = (zones_per_line - 1); k >= 0; k--)
191+
{
192+
if (Result->nb_target_detected[j+k]>0)
193+
{
194+
if (EnableSignal)
195+
{
196+
snprintf(report, sizeof(report),"| %5ld : ", (long)Result->signal_per_spad[(VL53L7CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
197+
SerialPort.print(report);
198+
}
199+
else
200+
{
201+
snprintf(report, sizeof(report),"| %5s : ", "X");
202+
SerialPort.print(report);
203+
}
204+
if (EnableAmbient)
205+
{
206+
snprintf(report, sizeof(report),"%5ld ", (long)Result->ambient_per_spad[j+k]);
207+
SerialPort.print(report);
208+
}
209+
else
210+
{
211+
snprintf(report, sizeof(report),"%5s ", "X");
212+
SerialPort.print(report);
213+
}
214+
}
215+
else
216+
{
217+
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");
218+
SerialPort.print(report);
219+
}
220+
}
221+
SerialPort.print("|\n");
222+
}
223+
}
224+
}
225+
for (i = 0; i < zones_per_line; i++)
226+
SerialPort.print(" -----------------");
227+
SerialPort.print("\n");
228+
}
229+
230+
void toggle_resolution(void)
231+
{
232+
sensor_vl53l7cx_top.vl53l7cx_stop_ranging();
233+
234+
switch (res)
235+
{
236+
case VL53L7CX_RESOLUTION_4X4:
237+
res = VL53L7CX_RESOLUTION_8X8;
238+
break;
239+
240+
case VL53L7CX_RESOLUTION_8X8:
241+
res = VL53L7CX_RESOLUTION_4X4;
242+
break;
243+
244+
default:
245+
break;
246+
}
247+
sensor_vl53l7cx_top.vl53l7cx_set_resolution(res);
248+
sensor_vl53l7cx_top.vl53l7cx_start_ranging();
249+
}
250+
251+
void toggle_signal_and_ambient(void)
252+
{
253+
EnableAmbient = (EnableAmbient) ? false : true;
254+
EnableSignal = (EnableSignal) ? false : true;
255+
}
256+
257+
void clear_screen(void)
258+
{
259+
snprintf(report, sizeof(report),"%c[2J", 27); /* 27 is ESC command */
260+
SerialPort.print(report);
261+
}
262+
263+
void display_commands_banner(void)
264+
{
265+
snprintf(report, sizeof(report),"%c[2H", 27); /* 27 is ESC command */
266+
SerialPort.print(report);
267+
268+
Serial.print("53L7A1 Simple Ranging demo application\n");
269+
Serial.print("--------------------------------------\n\n");
270+
271+
Serial.print("Use the following keys to control application\n");
272+
Serial.print(" 'r' : change resolution\n");
273+
Serial.print(" 's' : enable signal and ambient\n");
274+
Serial.print(" 'c' : clear screen\n");
275+
Serial.print("\n");
276+
}
277+
278+
void handle_cmd(uint8_t cmd)
279+
{
280+
switch (cmd)
281+
{
282+
case 'r':
283+
toggle_resolution();
284+
clear_screen();
285+
break;
286+
287+
case 's':
288+
toggle_signal_and_ambient();
289+
clear_screen();
290+
break;
291+
292+
case 'c':
293+
clear_screen();
294+
break;
295+
296+
default:
297+
break;
298+
}
299+
}

0 commit comments

Comments
 (0)