Hi,
I’ve connected [LiDAR Lite V3HP, 2 x [BH1750 and [ICM20948 to once I2C network over [QWIICBus Kit with cables shorter than 1m.
Currently I’m facing problem with unstable communication (once per some a view I2C communication tries, the I2C bus becomes unavailable). In other words, I’m facing communication issues over I2C while measuring distance with LiDAR LiDAR V3HP. I’m doing 40 reads with 0.01 sec delay and calculating average from it.
Python code:
def get_distance(self, expected_measurements_count=40) -> int:
"""
See description of get_distance method in DistanceSensorInterface class.
"""
distance_sum = 0
actual_measurements_count = 0
i2c_communication_errors = 0
while actual_measurements_count < expected_measurements_count:
try:
self.wait_until_not_busy()
self.write_reg("ACQ_COMMAND", 0x04)
self.wait_until_not_busy()
sensor_status = self.read_reg("STATUS")
if (sensor_status & (1 << 5)) and (sensor_status & (1 << 3)):
# Include measurement only when no error on LiDAR and peak detected.
distance_sum += self.read_reg2("FULL_DELAY")
actual_measurements_count += 1
time.sleep(0.01)
except OSError:
# It can happen that I2C communication issues can happen,
# while sending too many command in short period of time.
if i2c_communication_errors > 5:
raise
i2c_communication_errors += 1
return int(distance_sum / expected_measurements_count)
What I’ve tried already:
-
lower I2C speed frequency from 400kHz to 100kHz, but there is still the same problem,
-
disconnect 2 sensors. The problem was less frequent, but it still was.
Might it be that I’ve connected too many devices to QWIICBus or maybe rather QWIICBus Kit default settings are not the best one?](SparkFun QwiicBus Kit - KIT-17250 - SparkFun Electronics)](ICM-20948 9DoF - 3-axis accelerometer, gyroscope Botland - Robotic Shop)](Buy Light intensity sensor BH1750 Botland - Robotic Shop)](https://www.sparkfun.com/products/14599)