Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update driver usign ULD unmodified #7

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, STM32duino
Copyright (c) 2024, STM32duino

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Arduino library to support the VL53L8CX Time-of-Flight 8x8 multizone ranging sen

## API

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

## Examples
Expand Down
219 changes: 99 additions & 120 deletions examples/VL53L8CX_HelloWorld_I2C/VL53L8CX_HelloWorld_I2C.ino
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/**
******************************************************************************
* @file VL53L8CX_HelloWorld_I2C.ino
* @author STMicroelectronics
* @version V1.0.0
* @date 12 June 2023
* @brief Arduino test application for STMicroelectronics VL53L8CX
* proximity sensor satellite based on FlightSense.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/**
******************************************************************************
* @file VL53L8CX_HelloWorld_I2C.ino
* @author STMicroelectronics
* @version V2.0.0
* @date 27 June 2024
* @brief Arduino test application for STMicroelectronics VL53L8CX
* proximity sensor satellite based on FlightSense.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2024 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 these examples you need to connect the VL53L8CX satellite sensor directly to the Nucleo board with wires as explained below:
* pin 1 (SPI_I2C_n) of the VL53L8CX satellite connected to pin GND of the Nucleo board
* pin 1 (SPI_I2C_N) of the VL53L8CX satellite connected to pin GND of the Nucleo board
* pin 2 (LPn) of the VL53L8CX satellite connected to pin A3 of the Nucleo board
* pin 3 (NCS) not connected
* pin 4 (MISO) not connected
Expand All @@ -49,15 +49,14 @@
* pin 8 (I0VDD) of the VL53L8CX satellite not connected
* pin 9 (3V3) of the VL53L8CX satellite connected to 3V3 of the Nucleo board
* pin 10 (1V8) of the VL53L8CX satellite not connected
* pin 11 (5V) of the VL53L8CX satellite not connected
* pin 11 (5V) of the VL53L8CX satellite not connected
* GPIO1 of VL53L8CX satellite connected to A2 pin of the Nucleo board (not used)
* GND of the VL53L8CX satellite connected to GND of the Nucleo board
*/

/* Includes ------------------------------------------------------------------*/
#include <Arduino.h>
#include <Wire.h>
#include <vl53l8cx_class.h>

#include <vl53l8cx.h>


#ifdef ARDUINO_SAM_DUE
Expand All @@ -68,7 +67,6 @@
#define SerialPort Serial

#define LPN_PIN A3
#define I2C_RST_PIN -1
#define PWREN_PIN 11

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

// Components.
VL53L8CX sensor_vl53l8cx_top(&DEV_I2C, LPN_PIN, I2C_RST_PIN);
VL53L8CX sensor_vl53l8cx_top(&DEV_I2C, LPN_PIN);

bool EnableAmbient = false;
bool EnableSignal = false;
uint8_t res = VL53L8CX_RESOLUTION_4X4;
char report[256];
uint8_t status;

/* Setup ---------------------------------------------------------------------*/
void setup()
Expand All @@ -100,32 +99,30 @@ void setup()

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

// Configure VL53L8CX component.
sensor_vl53l8cx_top.begin();
sensor_vl53l8cx_top.init_sensor();
status = sensor_vl53l8cx_top.init();

// Start Measurements
sensor_vl53l8cx_top.vl53l8cx_start_ranging();
status = sensor_vl53l8cx_top.start_ranging();
}

void loop()
{
VL53L8CX_ResultsData Results;
uint8_t NewDataReady = 0;
uint8_t status;

do {
status = sensor_vl53l8cx_top.vl53l8cx_check_data_ready(&NewDataReady);
status = sensor_vl53l8cx_top.check_data_ready(&NewDataReady);
} while (!NewDataReady);

if ((!status) && (NewDataReady != 0)) {
status = sensor_vl53l8cx_top.vl53l8cx_get_ranging_data(&Results);
status = sensor_vl53l8cx_top.get_ranging_data(&Results);
print_result(&Results);
}

if (Serial.available()>0)
{
if (Serial.available() > 0) {
handle_cmd(Serial.read());
}
delay(100);
Expand All @@ -142,100 +139,83 @@ void print_result(VL53L8CX_ResultsData *Result)
display_commands_banner();

SerialPort.print("Cell Format :\n\n");

for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++)
{
snprintf(report, sizeof(report)," \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status");

for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++) {
snprintf(report, sizeof(report), " \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status");
SerialPort.print(report);

if(EnableAmbient || EnableSignal)
{
snprintf(report, sizeof(report)," %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
if (EnableAmbient || EnableSignal) {
snprintf(report, sizeof(report), " %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
SerialPort.print(report);
}
}

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

for (j = 0; j < number_of_zones; j += zones_per_line)
{
for (i = 0; i < zones_per_line; i++)
for (j = 0; j < number_of_zones; j += zones_per_line) {
for (i = 0; i < zones_per_line; i++) {
SerialPort.print(" -----------------");
}
SerialPort.print("\n");
for (i = 0; i < zones_per_line; i++)

for (i = 0; i < zones_per_line; i++) {
SerialPort.print("| ");
}
SerialPort.print("|\n");

for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++)
{
// Print distance and status
for (k = (zones_per_line - 1); k >= 0; k--)
{
if (Result->nb_target_detected[j+k]>0)
{
snprintf(report, sizeof(report),"| \033[38;5;10m%5ld\033[0m : %5ld ",
(long)Result->distance_mm[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l],
(long)Result->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
SerialPort.print(report);
}
else
{
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");

for (l = 0; l < VL53L8CX_NB_TARGET_PER_ZONE; l++) {
// Print distance and status
for (k = (zones_per_line - 1); k >= 0; k--) {
if (Result->nb_target_detected[j + k] > 0) {
snprintf(report, sizeof(report), "| \033[38;5;10m%5ld\033[0m : %5ld ",
(long)Result->distance_mm[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l],
(long)Result->target_status[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l]);
SerialPort.print(report);
} else {
snprintf(report, sizeof(report), "| %5s : %5s ", "X", "X");
SerialPort.print(report);
}
}
SerialPort.print("|\n");

if (EnableAmbient || EnableSignal )
{
// Print Signal and Ambient
for (k = (zones_per_line - 1); k >= 0; k--)
{
if (Result->nb_target_detected[j+k]>0)
{
if (EnableSignal)
{
snprintf(report, sizeof(report),"| %5ld : ", (long)Result->signal_per_spad[(VL53L8CX_NB_TARGET_PER_ZONE * (j+k)) + l]);
if (EnableAmbient || EnableSignal) {
// Print Signal and Ambient
for (k = (zones_per_line - 1); k >= 0; k--) {
if (Result->nb_target_detected[j + k] > 0) {
if (EnableSignal) {
snprintf(report, sizeof(report), "| %5ld : ", (long)Result->signal_per_spad[(VL53L8CX_NB_TARGET_PER_ZONE * (j + k)) + l]);
SerialPort.print(report);
}
else
{
snprintf(report, sizeof(report),"| %5s : ", "X");
} else {
snprintf(report, sizeof(report), "| %5s : ", "X");
SerialPort.print(report);
}
if (EnableAmbient)
{
snprintf(report, sizeof(report),"%5ld ", (long)Result->ambient_per_spad[j+k]);
if (EnableAmbient) {
snprintf(report, sizeof(report), "%5ld ", (long)Result->ambient_per_spad[j + k]);
SerialPort.print(report);
}
else
{
snprintf(report, sizeof(report),"%5s ", "X");
} else {
snprintf(report, sizeof(report), "%5s ", "X");
SerialPort.print(report);
}
}
else
{
snprintf(report, sizeof(report),"| %5s : %5s ", "X", "X");
} else {
snprintf(report, sizeof(report), "| %5s : %5s ", "X", "X");
SerialPort.print(report);
}
}
SerialPort.print("|\n");
}
}
}
for (i = 0; i < zones_per_line; i++)
SerialPort.print(" -----------------");
for (i = 0; i < zones_per_line; i++) {
SerialPort.print(" -----------------");
}
SerialPort.print("\n");
}

void toggle_resolution(void)
{
sensor_vl53l8cx_top.vl53l8cx_stop_ranging();
status = sensor_vl53l8cx_top.stop_ranging();

switch (res)
{
switch (res) {
case VL53L8CX_RESOLUTION_4X4:
res = VL53L8CX_RESOLUTION_8X8;
break;
Expand All @@ -247,8 +227,8 @@ void toggle_resolution(void)
default:
break;
}
sensor_vl53l8cx_top.vl53l8cx_set_resolution(res);
sensor_vl53l8cx_top.vl53l8cx_start_ranging();
status = sensor_vl53l8cx_top.set_resolution(res);
status = sensor_vl53l8cx_top.start_ranging();
}

void toggle_signal_and_ambient(void)
Expand All @@ -259,13 +239,13 @@ void toggle_signal_and_ambient(void)

void clear_screen(void)
{
snprintf(report, sizeof(report),"%c[2J", 27); /* 27 is ESC command */
snprintf(report, sizeof(report), "%c[2J", 27); /* 27 is ESC command */
SerialPort.print(report);
}

void display_commands_banner(void)
{
snprintf(report, sizeof(report),"%c[2H", 27); /* 27 is ESC command */
snprintf(report, sizeof(report), "%c[2H", 27); /* 27 is ESC command */
SerialPort.print(report);

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

void handle_cmd(uint8_t cmd)
{
switch (cmd)
{
switch (cmd) {
case 'r':
toggle_resolution();
clear_screen();
Expand Down
Loading