cancel
Showing results for 
Search instead for 
Did you mean: 

Reading several VL53L7CX sensors with a Nucleo

alyssaForum
Associate II

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:

  • each sensor is using a different I2C bus (sensor 1 is plugged on SDA1/SCL1, sensor 2 on SDA2/SCL2, etc)
  • the GND of each sensor is connected to the Nucleo’s mass
  • IOVDD and AVDD are respectively connected to 3.3V and 5V
  • the LPn pins are connected to 3 different GPIO pins (D2, D4, D6)

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!

3 REPLIES 3
TDK
Guru

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.

TDK_0-1693273076145.png

 

If you feel a post has answered your question, please click "Accept as Solution".

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(). 

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 


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'