cancel
Showing results for 
Search instead for 
Did you mean: 

I2C address problem with SATEL-VL53L7CX

alyssaForum
Associate II

Hello everyone,

I am trying to read the distance data from a VL53L7CX ToF sensor with a Teensy 4.1 board. I am using the SATEL-VL53L7CX breakout board.

The sensor is detected by the Teensy, however I when I try to check if the new data are ready to be read, it is never the case. I looked closely and found out that the I2C address detected by the Teensy (0x29) was different than the one used by the sensor (0x52, default address). Do you have any idea how to solve that please? 

Beside that, my sensor is correctly wired to the Teensy :

  • IC2_RST on pin 22 of the Teensy
  • SDA on pin 18
  • SCL on pin 19
  • LPn on pin 23
  • PWREN on pin 15
  • AVDD on 5V
  • IOVDD n 3.3V
  • GND on ground

Also, I am using the stm32duino VL53L7CX library (https://github.com/stm32duino/VL53L7CX/tree/main) and here is my code. 

 

/************* PARAMETERS *************/ 
#include <Arduino.h>
#include <Wire.h>
#include <vl53l7cx_class.h>

#define DEV_I2C Wire

#define LED_PIN 13
#define LPN_PIN 23
#define I2C_RST_PIN 22
#define PWREN_PIN 15

// Components
VL53L7CX sensor_vl53l7cx_top(&DEV_I2C, LPN_PIN, I2C_RST_PIN);

// Global param.
uint8_t res = VL53L7CX_RESOLUTION_4X4;
uint8_t ranging_mode = VL53L7CX_RANGING_MODE_CONTINUOUS;

/************* FONCTIONS *************/
// ToF initialisation
void tof_init(){
  // Enable PWREN pin if present
  if (PWREN_PIN >= 0) {
    pinMode(PWREN_PIN, OUTPUT);
    digitalWrite(PWREN_PIN, HIGH);
    delay(10);
  }
 
  // Init and start sensor
  sensor_vl53l7cx_top.begin();
  
  while (!sensor_vl53l7cx_top.init_sensor()) {
    Serial.println("Sensor not detected, check wiring");
    delay(100);
  }
  Serial.println("Sensor detected!");

  // Resolution
  sensor_vl53l7cx_top.vl53l7cx_set_resolution(res);

  // Ranging mode
  sensor_vl53l7cx_top.vl53l7cx_set_ranging_mode(ranging_mode);

  // Start measurements
  sensor_vl53l7cx_top.vl53l7cx_start_ranging();
}

// I2C address scanner
void i2c_scan(){
  byte error, address;
  int devices = 0;
  Serial.println("Scanning...");

  for (address = 1; address < 127; address++) {
    DEV_I2C.beginTransmission(address);
    error = DEV_I2C.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println(" !");
      devices++;
    }
  }

  if (devices == 0)
    Serial.println("No I2C devices found.");
}

/************* MAIN *************/
void setup()
{
  // Initialize serial for output
  Serial.begin(115200);
  Serial.println("Begin initialisation");

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

  // I2C address scanner
  i2c_scan();
  
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  Serial.println("Initialisation done");
}

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

  // Check if data ready
  do {
    status = sensor_vl53l7cx_top.vl53l7cx_check_data_ready(&NewDataReady);
  } while (!NewDataReady);

  // If yes, read it and print it
  if ((!status) && (NewDataReady != 0)) {
    status = sensor_vl53l7cx_top.vl53l7cx_get_ranging_data(&Results);

    // Compute the mean of all the distances (1 distance per zone)
    int32_t sum = 0;
    for (int i = 0; i < res*res; i++) {
      sum += Results.distance_mm[i];
    }

    String msg = "Distance : " + sum;
    Serial.println(msg);
  }
  
  delay(1000);
}

 

 

 PS : I have already tried to change the ToF sensor, the Teensy board and the code with the

VL53L7CX_HelloWorld example code from the library. I still have the same problem.
 
Thank you all for your help!
1 ACCEPTED SOLUTION

Accepted Solutions

Arduino World uses the 7-bit address as a low-order representation.

ST, and others, use a 7-bit address, sat within the 8-bit space, as the high-order 7-bits, as it presents on the wire of the interface. The low order bit being the R/W designation of the type of transaction.

One generally looks to the documentation to show the bit level signalling at a bus level for the example read/write to confirm the address bits as presented to the bus, and then align those based on an understanding of the platform / software side expectations of the host system. Then one confirms that the SLAVE acknowledges it's presence when addressed. One of the benefits of using I2C, you can probe and see if a device is present on the bus or not.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
TDK
Guru

HAL expects left-shifted addresses. Note that 0x52 = 0x29 * 2. Probably the issue here, at least with that part of it. There is nothing to solve about it, that's just how it is.

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

Arduino World uses the 7-bit address as a low-order representation.

ST, and others, use a 7-bit address, sat within the 8-bit space, as the high-order 7-bits, as it presents on the wire of the interface. The low order bit being the R/W designation of the type of transaction.

One generally looks to the documentation to show the bit level signalling at a bus level for the example read/write to confirm the address bits as presented to the bus, and then align those based on an understanding of the platform / software side expectations of the host system. Then one confirms that the SLAVE acknowledges it's presence when addressed. One of the benefits of using I2C, you can probe and see if a device is present on the bus or not.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you! I’ll take a closer look at this!