Skip to content
Snippets Groups Projects
Commit 0db73f0f authored by Rene Ebeling's avatar Rene Ebeling
Browse files

changed the ST library to the library from the vl53l7cx

parent d51f6c72
Branches
No related tags found
No related merge requests found
/**
******************************************************************************
* @file VL53L5CX_Sat_HelloWorld.ino
* @file VL53L7CX_Sat_HelloWorld.ino
* @author STMicroelectronics
* @version V1.0.0
* @date 11 November 2021
* @brief Arduino test application for the STMicrolectronics VL53L5CX
* @brief Arduino test application for the STMicrolectronics VL53L7CX
* proximity sensor satellite based on FlightSense.
* This application makes use of C++ classes obtained from the C
* components' drivers.
......@@ -38,22 +38,22 @@
******************************************************************************
*/
/*
* To use these examples you need to connect the VL53L5CX satellite sensor directly to the Nucleo board with wires as explained below:
* pin 1 (GND) of the VL53L5CX satellite connected to GND of the Nucleo board
* pin 2 (IOVDD) of the VL53L5CX satellite connected to 3V3 pin of the Nucleo board
* pin 3 (AVDD) of the VL53L5CX satellite connected to 5V pin of the Nucleo board
* pin 4 (PWREN) of the VL53L5CX satellite connected to pin A5 of the Nucleo board
* pin 5 (LPn) of the VL53L5CX satellite connected to pin A3 of the Nucleo board
* pin 6 (SCL) of the VL53L5CX satellite connected to pin D15 (SCL) of the Nucleo board
* pin 7 (SDA) of the VL53L5CX satellite connected to pin D14 (SDA) of the Nucleo board
* pin 8 (I2C_RST) of the VL53L5CX satellite connected to pin A1 of the Nucleo board
* pin 9 (INT) of the VL53L5CX satellite connected to pin A2 of the Nucleo board
* To use these examples you need to connect the VL53L7CX satellite sensor directly to the Nucleo board with wires as explained below:
* pin 1 (GND) of the VL53L7CX satellite connected to GND of the Nucleo board
* pin 2 (IOVDD) of the VL53L7CX satellite connected to 3V3 pin of the Nucleo board
* pin 3 (AVDD) of the VL53L7CX satellite connected to 5V pin of the Nucleo board
* pin 4 (PWREN) of the VL53L7CX satellite connected to pin A5 of the Nucleo board
* pin 5 (LPn) of the VL53L7CX satellite connected to pin A3 of the Nucleo board
* pin 6 (SCL) of the VL53L7CX satellite connected to pin D15 (SCL) of the Nucleo board
* pin 7 (SDA) of the VL53L7CX satellite connected to pin D14 (SDA) of the Nucleo board
* pin 8 (I2C_RST) of the VL53L7CX satellite connected to pin A1 of the Nucleo board
* pin 9 (INT) of the VL53L7CX satellite connected to pin A2 of the Nucleo board
*/
/* Includes ------------------------------------------------------------------*/
#include <Arduino.h>
#include <Wire.h>
#include <ArduinoJson.h>
#include <vl53l5cx_class.h>
#include <vl53l7cx_class.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -61,19 +61,19 @@
#include <assert.h>
#include <stdlib.h>
#define DEV_I2C Wire
#define DEV_I2C1 Wire1
#define DEV_I2C0 Wire
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
#define LedPin LED_BUILTIN
#define LPN_PIN0 3
#define LPN_PIN0 14
#define I2C_RST_PIN0 27
#define PWREN_PIN 27
#define LPN_PIN1 7
#define LPN_PIN1 15
#define I2C_RST_PIN1 27
#define PWREN_PIN 27
......@@ -93,14 +93,15 @@ uint16_t sensoraddress3 = 0x67;
uint16_t wait_for_i2c = 50;
uint16_t imageWidth = 8;
uint16_t ranging_frequency = 15;
pin_size_t SDA1_PIN = 6;
pin_size_t SCL1_PIN = 7;
JsonDocument doc;
// Components.
VL53L5CX sensor0(&DEV_I2C, LPN_PIN0, I2C_RST_PIN0);
VL53L5CX sensor1(&DEV_I2C, LPN_PIN1, I2C_RST_PIN1);
VL53L5CX sensor2(&DEV_I2C, LPN_PIN2, I2C_RST_PIN2);
VL53L5CX sensor3(&DEV_I2C, LPN_PIN2, I2C_RST_PIN2);
VL53L7CX sensor0(&DEV_I2C0, LPN_PIN0, I2C_RST_PIN0);
VL53L7CX sensor1(&DEV_I2C0, LPN_PIN1, I2C_RST_PIN1);
VL53L7CX sensor2(&DEV_I2C0, LPN_PIN2, I2C_RST_PIN2);
VL53L7CX sensor3(&DEV_I2C0, LPN_PIN2, I2C_RST_PIN2);
void blink_led_loop(void);
......@@ -139,8 +140,12 @@ void setup()
Serial.println("Initialize... Please wait, it may take few seconds...");
// Initialize I2C bus.
DEV_I2C.begin();
DEV_I2C.setClock(1000000);
DEV_I2C0.begin();
DEV_I2C0.setClock(1000000);
delay(50);
DEV_I2C1.begin();
DEV_I2C1.setClock(1000000);
delay(50);
// Initialize and configure sensors
......@@ -163,10 +168,10 @@ void setup()
void loop() {
// Declare the result data variables for each sensor
VL53L5CX_ResultsData Results0;
VL53L5CX_ResultsData Results1;
VL53L5CX_ResultsData Results2;
VL53L5CX_ResultsData Results3;
VL53L7CX_ResultsData Results0;
VL53L7CX_ResultsData Results1;
VL53L7CX_ResultsData Results2;
VL53L7CX_ResultsData Results3;
// Process each sensor data and save to respective JSON arrays
processSensorData(sensor0, Results0, doc["sensor0"].to<JsonArray>(), "sensor0");
......@@ -196,7 +201,7 @@ void i2cScanner()
delay(wait_for_i2c);
}
void initializeSensor(VL53L5CX &sensor, uint16_t sensorAddress, int lpnPin, int i2cRstPin) {
void initializeSensor(VL53L7CX &sensor, uint16_t sensorAddress, int lpnPin, int i2cRstPin) {
digitalWrite(lpnPin, HIGH); // Activate sensor power
delay(wait_for_i2c);
......@@ -206,30 +211,30 @@ void initializeSensor(VL53L5CX &sensor, uint16_t sensorAddress, int lpnPin, int
delay(wait_for_i2c);
// Set I2C address
sensor.vl53l5cx_set_i2c_address(sensorAddress << 1);
sensor.vl53l7cx_set_i2c_address(sensorAddress << 1);
delay(wait_for_i2c);
// Set resolution and frequency
sensor.vl53l5cx_set_resolution(VL53L5CX_RESOLUTION_8X8);
sensor.vl53l7cx_set_resolution(VL53L7CX_RESOLUTION_8X8);
delay(wait_for_i2c);
sensor.vl53l5cx_set_ranging_frequency_hz(ranging_frequency);
sensor.vl53l7cx_set_ranging_frequency_hz(ranging_frequency);
delay(wait_for_i2c);
// Start ranging
sensor.vl53l5cx_start_ranging();
sensor.vl53l7cx_start_ranging();
delay(wait_for_i2c);
// Reset LPN and I2C pins
digitalWrite(lpnPin, LOW);
}
void processSensorData(VL53L5CX &sensor, VL53L5CX_ResultsData &results, const JsonArray& data, const char* sensorKey) {
void processSensorData(VL53L7CX &sensor, VL53L7CX_ResultsData &results, const JsonArray& data, const char* sensorKey) {
uint8_t NewDataReady = 0;
uint8_t status;
// Wait for data to be ready
do {
status = sensor.vl53l5cx_check_data_ready(&NewDataReady);
status = sensor.vl53l7cx_check_data_ready(&NewDataReady);
} while (!NewDataReady);
// Turn LED on to indicate data processing
......@@ -237,13 +242,13 @@ void processSensorData(VL53L5CX &sensor, VL53L5CX_ResultsData &results, const Js
// If data is ready, get the ranging data and store it in the JSON array
if ((!status) && (NewDataReady != 0)) {
status = sensor.vl53l5cx_get_ranging_data(&results);
status = sensor.vl53l7cx_get_ranging_data(&results);
JsonArray sensorData = doc[sensorKey].to<JsonArray>();
// Process the results and add them to the JSON array
for (int y = imageWidth * (imageWidth - 1); y >= 0; y -= imageWidth) {
for (int x = 0; x <= imageWidth - 1; x++) {
sensorData.add(results.distance_mm[VL53L5CX_NB_TARGET_PER_ZONE * (x + y)]);
sensorData.add(results.distance_mm[VL53L7CX_NB_TARGET_PER_ZONE * (x + y)]);
}
}
}
......
images/pico-gpios-600x422.png

105 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment