I2C address problem with SATEL-VL53L7CX
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
