Unstable I2C connection with LiDAR Lite V3HP

Hi,

I would like to ask if you have experienced communication problems with [LiDAR Lite V3HP over I2C bus?

More specifically, I have connected LiDAR to RasperryPi4 via [QWIICBus Kit and I can establish communication with the device.

The code I am using can be found here: https://pypi.org/project/LiDAR-Lite/#files.

Sometimes, however, I get an OSError error: [Errno 121] Remote I/O, which indicates that the device is not connected to the I2C bus.

The function that I use for measurements:

    def get_distance(self, expected_measurements_count=40) -> int:

        distance_sum = 0
        actual_measurements_count = 0
        while actual_measurements_count < expected_measurements_count:
            self.wait_until_not_busy()
            self.write_reg("ACQ_COMMAND", 0x04)
            self.wait_until_not_busy()
            sensor_status = self.read_reg("STATUS")
            if not (sensor_status & (1 << 5)):
                continue  # Skip measurement, when fault on LiDAR sensor.
            if not (sensor_status & (1 << 3)):
                continue  # Skip measurement, when no peak detected.
            actual_measurements_count += 1
            distance_sum += self.read_reg2("FULL_DELAY")
            time.sleep(0.1)
        return int(distance_sum / expected_measurements_count)

The sensor is configured with the following settings:

SIG_COUNT_VAL (register number: 0x02) - 0x1D

THRESHOLD_BYPASS (register number: 0x1C) - 0x00

ACQ_CONFIG_REG (register number: 0x04) - bits 2 and 4 are set to True

REF_COUNT_VAL (register number: 0x12) - 0xFF

Do you have any advice where the problem can be?

Might it be that LiDAR is getting stuck for some reason?

Or it is rather issue of subsystem installed on RP4, which is using I2C Bus to communicate with other devices?](SparkFun QwiicBus Kit - KIT-17250 - SparkFun Electronics)](https://www.sparkfun.com/products/14599)

Try a low I2C speed.

Seems the LIdar is using clock stretching and the chip on the RPI ( BCM2711) is known to have a problem with that. (e.g. see https://forums.raspberrypi.com/viewtopic.php?t=302381). In the past, I have created an I2C library that can handle clock stretching (https://github.com/paulvha/twowire), but you can also try to reduce the speed to 35Khz. Then the Lidar clock stretch might fall within the normal clock cycle.

Thank you @ paulvha for response.

Unfortunately it’s not the matter of I2C speed. I’ve check and on 100kHz and 35kHz, the problem still exists.

How do we know that LiDAR uses clock-skrething? There is nothing about it in documentation.

There is indeed nothing in datasheet that talks about it, but that is also missing for other sensors that turned out to use clock stretching. The only way to find out is a logic analyser. Other people suffered from garbage and looking at other posts they added a capacitor 680uf on the power, shortened the wires .

Indeed, that is also what is recommended in documentation.

Do you think it can improve stability? To me, it looks like problem on I2C bus.

Do you think it could be caused by the [QWIICBus Kit?](SparkFun QwiicBus Kit - KIT-17250 - SparkFun Electronics)

Could be. I would try to remove as much as possible (hardware / software) to get to a stable situation and then add from there.

What puillup voltage do you have on the I2C bus

I2C communication issues are caused by QWIICBus Bus Kit most probably.

See viewtopic.php?f=105&t=56742&p=229798#p229798.

Topic can be closed.