Skip to content

Commit aea6799

Browse files
authored
Merge pull request #7 from davideq/main
Update driver usign ULD unmodified
2 parents 5bca7f3 + 825cf3d commit aea6799

23 files changed

+5644
-5160
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2023, STM32duino
3+
Copyright (c) 2024, STM32duino
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Arduino library to support the VL53L8CX Time-of-Flight 8x8 multizone ranging sen
33

44
## API
55

6-
This sensor uses I2C to communicate. And I2C instance is required to access to the sensor.
6+
This sensor uses I2C/SPI to communicate. And I2C/SPI instance is required to access to the sensor.
77
The APIs provide simple distance measure and multizone detection in both polling and interrupt modes.
88

99
## Examples

examples/VL53L8CX_HelloWorld_I2C/VL53L8CX_HelloWorld_I2C.ino

Lines changed: 99 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
/**
2-
******************************************************************************
3-
* @file VL53L8CX_HelloWorld_I2C.ino
4-
* @author STMicroelectronics
5-
* @version V1.0.0
6-
* @date 12 June 2023
7-
* @brief Arduino test application for STMicroelectronics VL53L8CX
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-
*/
1+
/**
2+
******************************************************************************
3+
* @file VL53L8CX_HelloWorld_I2C.ino
4+
* @author STMicroelectronics
5+
* @version V2.0.0
6+
* @date 27 June 2024
7+
* @brief Arduino test application for STMicroelectronics VL53L8CX
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) 2024 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+
*/
4040
/*
4141
* To use these examples you need to connect the VL53L8CX satellite sensor directly to the Nucleo board with wires as explained below:
42-
* pin 1 (SPI_I2C_n) of the VL53L8CX satellite connected to pin GND of the Nucleo board
42+
* pin 1 (SPI_I2C_N) of the VL53L8CX satellite connected to pin GND of the Nucleo board
4343
* pin 2 (LPn) of the VL53L8CX satellite connected to pin A3 of the Nucleo board
4444
* pin 3 (NCS) not connected
4545
* pin 4 (MISO) not connected
@@ -49,15 +49,14 @@
4949
* pin 8 (I0VDD) of the VL53L8CX satellite not connected
5050
* pin 9 (3V3) of the VL53L8CX satellite connected to 3V3 of the Nucleo board
5151
* pin 10 (1V8) of the VL53L8CX satellite not connected
52-
* pin 11 (5V) of the VL53L8CX satellite not connected
52+
* pin 11 (5V) of the VL53L8CX satellite not connected
5353
* GPIO1 of VL53L8CX satellite connected to A2 pin of the Nucleo board (not used)
5454
* GND of the VL53L8CX satellite connected to GND of the Nucleo board
5555
*/
56-
56+
5757
/* Includes ------------------------------------------------------------------*/
58-
#include <Arduino.h>
59-
#include <Wire.h>
60-
#include <vl53l8cx_class.h>
58+
59+
#include <vl53l8cx.h>
6160

6261

6362
#ifdef ARDUINO_SAM_DUE
@@ -68,7 +67,6 @@
6867
#define SerialPort Serial
6968

7069
#define LPN_PIN A3
71-
#define I2C_RST_PIN -1
7270
#define PWREN_PIN 11
7371

7472
void print_result(VL53L8CX_ResultsData *Result);
@@ -77,12 +75,13 @@ void handle_cmd(uint8_t cmd);
7775
void display_commands_banner(void);
7876

7977
// Components.
80-
VL53L8CX sensor_vl53l8cx_top(&DEV_I2C, LPN_PIN, I2C_RST_PIN);
78+
VL53L8CX sensor_vl53l8cx_top(&DEV_I2C, LPN_PIN);
8179

8280
bool EnableAmbient = false;
8381
bool EnableSignal = false;
8482
uint8_t res = VL53L8CX_RESOLUTION_4X4;
8583
char report[256];
84+
uint8_t status;
8685

8786
/* Setup ---------------------------------------------------------------------*/
8887
void setup()
@@ -100,32 +99,30 @@ void setup()
10099

101100
// Initialize I2C bus.
102101
DEV_I2C.begin();
103-
102+
104103
// Configure VL53L8CX component.
105104
sensor_vl53l8cx_top.begin();
106-
sensor_vl53l8cx_top.init_sensor();
107-
105+
status = sensor_vl53l8cx_top.init();
106+
108107
// Start Measurements
109-
sensor_vl53l8cx_top.vl53l8cx_start_ranging();
108+
status = sensor_vl53l8cx_top.start_ranging();
110109
}
111110

112111
void loop()
113112
{
114113
VL53L8CX_ResultsData Results;
115114
uint8_t NewDataReady = 0;
116-
uint8_t status;
117115

118116
do {
119-
status = sensor_vl53l8cx_top.vl53l8cx_check_data_ready(&NewDataReady);
117+
status = sensor_vl53l8cx_top.check_data_ready(&NewDataReady);
120118
} while (!NewDataReady);
121119

122120
if ((!status) && (NewDataReady != 0)) {
123-
status = sensor_vl53l8cx_top.vl53l8cx_get_ranging_data(&Results);
121+
status = sensor_vl53l8cx_top.get_ranging_data(&Results);
124122
print_result(&Results);
125123
}
126124

127-
if (Serial.available()>0)
128-
{
125+
if (Serial.available() > 0) {
129126
handle_cmd(Serial.read());
130127
}
131128
delay(100);
@@ -142,100 +139,83 @@ void print_result(VL53L8CX_ResultsData *Result)
142139
display_commands_banner();
143140

144141
SerialPort.print("Cell Format :\n\n");
145-
146-
for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++)
147-
{
148-
snprintf(report, sizeof(report)," \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status");
142+
143+
for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++) {
144+
snprintf(report, sizeof(report), " \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status");
149145
SerialPort.print(report);
150146

151-
if(EnableAmbient || EnableSignal)
152-
{
153-
snprintf(report, sizeof(report)," %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
147+
if (EnableAmbient || EnableSignal) {
148+
snprintf(report, sizeof(report), " %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
154149
SerialPort.print(report);
155150
}
156151
}
157152

158153
SerialPort.print("\n\n");
159154

160-
for (j = 0; j < number_of_zones; j += zones_per_line)
161-
{
162-
for (i = 0; i < zones_per_line; i++)
155+
for (j = 0; j < number_of_zones; j += zones_per_line) {
156+
for (i = 0; i < zones_per_line; i++) {
163157
SerialPort.print(" -----------------");
158+
}
164159
SerialPort.print("\n");
165-
166-
for (i = 0; i < zones_per_line; i++)
160+
161+
for (i = 0; i < zones_per_line; i++) {
167162
SerialPort.print("| ");
163+
}
168164
SerialPort.print("|\n");
169-
170-
for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++)
171-
{
172-
// Print distance and status
173-
for (k = (zones_per_line - 1); k >= 0; k--)
174-
{
175-
if (Result->nb_target_detected[j+k]>0)
176-
{
177-
snprintf(report, sizeof(report),"| \033[38;5;10m%5ld\033[0m : %5ld ",
178-
(long)Result->distance_mm[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l],
179-
(long)Result->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
180-
SerialPort.print(report);
181-
}
182-
else
183-
{
184-
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");
165+
166+
for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++) {
167+
// Print distance and status
168+
for (k = (zones_per_line - 1); k >= 0; k--) {
169+
if (Result->nb_target_detected[j + k] > 0) {
170+
snprintf(report, sizeof(report), "| \033[38;5;10m%5ld\033[0m : %5ld ",
171+
(long)Result->distance_mm[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l],
172+
(long)Result->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l]);
173+
SerialPort.print(report);
174+
} else {
175+
snprintf(report, sizeof(report), "| %5s : %5s ", "X", "X");
185176
SerialPort.print(report);
186177
}
187178
}
188179
SerialPort.print("|\n");
189180

190-
if (EnableAmbient || EnableSignal )
191-
{
192-
// Print Signal and Ambient
193-
for (k = (zones_per_line - 1); k >= 0; k--)
194-
{
195-
if (Result->nb_target_detected[j+k]>0)
196-
{
197-
if (EnableSignal)
198-
{
199-
snprintf(report, sizeof(report),"| %5ld : ", (long)Result->signal_per_spad[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
181+
if (EnableAmbient || EnableSignal) {
182+
// Print Signal and Ambient
183+
for (k = (zones_per_line - 1); k >= 0; k--) {
184+
if (Result->nb_target_detected[j + k] > 0) {
185+
if (EnableSignal) {
186+
snprintf(report, sizeof(report), "| %5ld : ", (long)Result->signal_per_spad[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l]);
200187
SerialPort.print(report);
201-
}
202-
else
203-
{
204-
snprintf(report, sizeof(report),"| %5s : ", "X");
188+
} else {
189+
snprintf(report, sizeof(report), "| %5s : ", "X");
205190
SerialPort.print(report);
206191
}
207-
if (EnableAmbient)
208-
{
209-
snprintf(report, sizeof(report),"%5ld ", (long)Result->ambient_per_spad[j+k]);
192+
if (EnableAmbient) {
193+
snprintf(report, sizeof(report), "%5ld ", (long)Result->ambient_per_spad[j + k]);
210194
SerialPort.print(report);
211-
}
212-
else
213-
{
214-
snprintf(report, sizeof(report),"%5s ", "X");
195+
} else {
196+
snprintf(report, sizeof(report), "%5s ", "X");
215197
SerialPort.print(report);
216198
}
217-
}
218-
else
219-
{
220-
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");
199+
} else {
200+
snprintf(report, sizeof(report), "| %5s : %5s ", "X", "X");
221201
SerialPort.print(report);
222202
}
223203
}
224204
SerialPort.print("|\n");
225205
}
226206
}
227207
}
228-
for (i = 0; i < zones_per_line; i++)
229-
SerialPort.print(" -----------------");
208+
for (i = 0; i < zones_per_line; i++) {
209+
SerialPort.print(" -----------------");
210+
}
230211
SerialPort.print("\n");
231212
}
232213

233214
void toggle_resolution(void)
234215
{
235-
sensor_vl53l8cx_top.vl53l8cx_stop_ranging();
216+
status = sensor_vl53l8cx_top.stop_ranging();
236217

237-
switch (res)
238-
{
218+
switch (res) {
239219
case VL53L8CX_RESOLUTION_4X4:
240220
res = VL53L8CX_RESOLUTION_8X8;
241221
break;
@@ -247,8 +227,8 @@ void toggle_resolution(void)
247227
default:
248228
break;
249229
}
250-
sensor_vl53l8cx_top.vl53l8cx_set_resolution(res);
251-
sensor_vl53l8cx_top.vl53l8cx_start_ranging();
230+
status = sensor_vl53l8cx_top.set_resolution(res);
231+
status = sensor_vl53l8cx_top.start_ranging();
252232
}
253233

254234
void toggle_signal_and_ambient(void)
@@ -259,13 +239,13 @@ void toggle_signal_and_ambient(void)
259239

260240
void clear_screen(void)
261241
{
262-
snprintf(report, sizeof(report),"%c[2J", 27); /* 27 is ESC command */
242+
snprintf(report, sizeof(report), "%c[2J", 27); /* 27 is ESC command */
263243
SerialPort.print(report);
264244
}
265245

266246
void display_commands_banner(void)
267247
{
268-
snprintf(report, sizeof(report),"%c[2H", 27); /* 27 is ESC command */
248+
snprintf(report, sizeof(report), "%c[2H", 27); /* 27 is ESC command */
269249
SerialPort.print(report);
270250

271251
Serial.print("53L8A1 Simple Ranging demo application\n");
@@ -280,8 +260,7 @@ void display_commands_banner(void)
280260

281261
void handle_cmd(uint8_t cmd)
282262
{
283-
switch (cmd)
284-
{
263+
switch (cmd) {
285264
case 'r':
286265
toggle_resolution();
287266
clear_screen();

0 commit comments

Comments
 (0)