2023-08-28 6:27 PM
Hello everyone,
I am trying to read data from three SATEL-VL53L7CX, using only their mini-PCB part, with a Nucleo F401RE.
To do so, I did the following wiring:
I am using Arduino IDE to develop the code. Here it is:
/************************** INCLUDES **************************/
#include <Arduino.h>
#include <Wire.h>
#include <vl53l7cx_class.h>
#include <stdio.h>
#define DEV_I2C Wire
#define SerialPort Serial
#define LED_PIN PC13
#define TOF 3                     // number of ToF
          
#define LPN_PIN1 3                // sensor #1 wiring 
#define LPN_PIN2 5                // sensor #2 wiring 
#define LPN_PIN3 7                // sensor #3 wiring 
/************************** PARAMETERS **************************/
// Components.
VL53L7CX sensor1(&DEV_I2C, LPN_PIN1);
VL53L7CX sensor2(&DEV_I2C, LPN_PIN2);
VL53L7CX sensor3(&DEV_I2C, LPN_PIN3);
VL53L7CX* tab_sensor[] = {&sensor1, &sensor2, &sensor3};
// Global param.
uint8_t res = VL53L7CX_RESOLUTION_4X4;
uint8_t ranging_mode = VL53L7CX_RANGING_MODE_CONTINUOUS;
uint8_t address[] = {0x54, 0x56, 0x58};             // sensors' I2C address 
uint8_t status;
/************************** MAIN **************************/
void setup()
{
  // Initialize serial for output.
  SerialPort.begin(115200);
  while (!Serial) ;
  SerialPort.println("------- BEGIN INITIALISATION -------\n");
  
  // Initialize I2C bus.
  DEV_I2C.begin();
  // ToF initialisation
  if(tof_init() == -1)  return;
  // Indicate end of initialisation
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
  Serial.println("------- INITIALISATION DONE -------\n\n");
}
void loop()
{
}
/************************** FUNCTIONS **************************/
// ToF initialisation
int tof_init(){
  for(size_t i = 0; i < TOF; i++){
    // Put all LPn pins to low to disable I2C com.
    tab_sensor[i]->begin();
    SerialPort.print("Begin sensor #"); SerialPort.print(i); SerialPort.print(" OK\n");
  }
  for(size_t i = 0; i < TOF; i++){
    // Init sensor
    status = tab_sensor[i]->init_sensor(address[i]);
    if(status == 0)         {SerialPort.print("Init sensor OK\n");}
    else                    {SerialPort.print("ERROR INIT SENSOR\n"); return -1;}
    // Ranging mode
    status = tab_sensor[i]->vl53l7cx_set_ranging_mode(ranging_mode);
    if(status == 0)         SerialPort.print("Ranging mode OK\n");
    else                    {SerialPort.print("ERROR RANGING MODE\n"); return -1;}
    // Resolution
    status = tab_sensor[i]->vl53l7cx_set_resolution(res);
    if(status == 0)         SerialPort.print("Resolution initialisation OK\n");
    else                    {SerialPort.print("ERROR RESOLUTION INITIALISATION\n"); return -1;}
    // Start Measurements
    status = tab_sensor[i]->vl53l7cx_start_ranging();
    if(status == 0)         SerialPort.print("Start ranging OK\n");
    else                    {SerialPort.print("ERROR START RANGING\n"); return -1;}
    SerialPort.print("Initialisation sensor #"); SerialPort.print(i); SerialPort.print(" done\n\n");
  }
  return 0;
}The problem is that I can’t initialise my sensors. When I keep the default I2C address for all the sensors, the 1st sensor tries to initialise forever without never returning any error or success code. When I try to initialise each sensor with a different address (0x54, 0x56, …), the init_sensor method returns an error value (value different from 0). I feel like the sensors are not detected at all by the Nucleo board…
Could anyone help me on what I am doing wrong here please?
Thanks a lot!
2023-08-28 6:38 PM
The chip is programmed to respond to a particular address. In this case it's 0x52. You don't get to pick what address you use.
2023-08-28 6:45 PM
This is what I did in the first place, I initialized the sensors without specifying any address in order to use the default one. But in this case, the code is "blocked" at the 1st sensor being initialized: no value (0 or different from 0) is never returned by init_sensor().
2023-10-11 3:52 AM
Hello
Did you have a look to the examples delivered within the x-Cube-ToF1 package ?
You can find an example code with multiple sensors ranging and the way to program the I2C.
Regards
Anne