How many devices can be connected to the I2C devices over QWIICBus?

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)

QWIIC bus is technically I2C or Twowire. The maximum number of devices is 127 (although some addresses are reserved).

I2C lines always need a pull-up resistor to show a ‘1’ and will pull the line low to show a ‘0’. I think your issue might be multiple pull-up resistors.

  • For the lidar the suggestion is to use 4k7 external (and even only for long lines?) Which makes sense if nothing else is connected.

  • However the BH1750 has already built-in resistors 4.7 kΩ pulling up the lines SCL and SDA of the I2C bus

  • To make things worse… the ICM20948 has already 10K pull-up resistors.
  • If you connect those resistors in parallel to the same (SDA or SCL) line the parallel resistor value becomes 1.9K and for some pins, it might result and that they can not pull it ‘low’ enough.

    Try each sensor by itself and then try the Lidar with one of the other sensors, BUT don’t use the 4k7 external pull-up

    You are right, I unknowingly connected several pull-up resistors to one I2C network. One small remark, according to [pinout or [electrical drawing, BH1750 has 10kΩ pull-up resistors, not 4.7kΩ.

    Here is exact topology of I2C network:

    I checked the impact of BH1750 sensors and I2C speed on the I2C bus communication quality.

    Here are results: https://we.tl/t-bBP0UiNtLZ

    (I couldn’t upload more than 3 images, so I uploaded them to WeTransfer)

    I noticed that every time the LiDAR stops responding there is a small peak on the I2C data bus.

    Here is screen of successful read from LiDAR, noice and LiDAR does not ACK frame anymore:

    This error occurs both with and without the BH1750 sensors connected. At lower speeds it occurs much less frequently, but it also occurs.](Adafruit Learning System)](Pinouts | Adafruit BH1750 Ambient Light Sensor | Adafruit Learning System)

    Thanks

    On the pull-up I used the info that was on the Botland page of the BH1750 " Built-in resistors 4.7 kΩ pulling up the lines SCL and SDA of the I2C bus", but good to know.

    I think you have a challenging set up with many points where it can fail/create noise.

  • The cable can act as a capacitor and impact the signal quality.

  • Different lengths in the cable between the sensor can mean more time to travel (we are talking about Microseconds).

  • Power consumption can have an impact (see whether you see spikes on the power maybe at the time you see noise on the line).

  • Instead of powering with QWIIC, power VCC-1 rail with 5V (there is a remark on the schematics of how to do that and also that the chip (PCA9615) works better with 5V
  • 1) The cable can act as a capacitor and impact the signal quality.

    I’ve already tried to shorten a few of them (oven to 0,5m RJ45 cable)

    2) Different lengths in the cable between the sensor can mean more time to travel (we are talking about Microseconds).

    At lower speed frequencies it also happened to me.

    3) Power consumption can have an impact (see whether you see spikes on the power maybe at the time you see noise on the line).

    I do.

    Please, see below sceen-shoots:

    I can’t find the exact source of these peaks, but I know it is somehow related to the current flowing.

    I noticed that the problem occurs when I switch the relay on the [UniPi 1.1.

    So I checked the following.

    When I unplugged the cables from the relay (they were connected to Normally Closed and COM) then after switching the relay there was no error while communicating with LiDAR. When the cables are plugged to the relay and it’s toggled, then error occurs.

    Maybe important is that there is 230VAC connected to relay COM.

    4) Instead of powering with QWIIC, power VCC-1 rail with 5V (there is a remark on the schematics of how to do that and also that the chip (PCA9615) works better with 5V

    It’s already working on 5V in my case.](Unipi 1.1 | Unipi)

    I’ve measured with multi-meter the resistance between Vcc and SDA/SCL in a whole circuit. In my case it’s 500Ω.

    500Ω is low. Although that causes a max current of 5/500 ~ 10mA on a pin, most pins can handle it. BUT there is often an internal resistance between GND and PIN that can impact signal low level on the line / quality. That said I did not detect that issue on your scope pictures

    However, your issue on the relay switching is of more concern. We see often a spike when a relay switches off because of the coil and then a flyback diode parallel to the coil needs to be set. Not sure that is the case on your board, I assume it has else you would have the problem with and without 230AC on the contacts.

    You only see the issue when the 230V / load is switched. Now, these spikes may come from an arc on the contact (when they are JUST very close still). Is your 230AC load inductive or is it a lamp? (else try a lamp or light load) There are Arc suppression technics ( e.g. look at https://testguy.net/content/362-Arc-sup … n-circuits or https://sound-au.com/articles/relays2.htm)

    My load was inductive (motor), therefore I’ve changed it to lamp (for a test purpose).

    And it’s still the same.

    I’ve changed UniPi power-supply for laboratory one, but also it did not help.

    What surprises me more is that even if I connect the lamp to the power-extender from which the power is taken to the UniPi, I still get interference on the I2C bus (PS. I tried to use different good quality power-extenders).

    See video:

    https://www.youtube.com/watch?v=p-k9daYUK58

    A video on youtube to show what happens… cool :slight_smile:

    Running out of ideas… but It still looks to be an arc / spikes causing this.

    These spikes could impact the 230 power and thus enter into your circuit through the power supply AND/OR it could cause spikes on the I2C cable and thus enter your circuit through the I2C bus.

    Out of the box thinking

  • Is I2c cabling shielded and if so is it probably grounded?

  • Try to move these cables as far away from 230V lines.

  • Are the QWICC bus mid-point and end-point shielded somehow? Maybe the spikes are entering there?

  • Is there a glitch or very small spike on the DC supply line the moment you connect the lamp

  • Try using another 230V power connection point in the house for the lamp and UniPi. Maybe one that is not connected to the same 230V fuse in the fusebox. Maybe a loaded group or bad connection in the in-house wire somewhere?

  • If you happen to have it, connect a small capacitor across the DC power supply (https://en.wikipedia.org/wiki/Decoupling_capacitor)

  • Is there a ground loop issue? Don’t know about your place but here in the old days in The Netherlands, the 230V NULL was connected directly to GND. If you have a “weak” ground connection a change on the NULL would then impact the GND level and impact your circuit. These days however the NULL is not connected locally to GND anymore. BUT could there be something in your situation?
  • Is I2c cabling shielded and if so is it probably grounded?

    No, cables are neither grounded nor shielded.

    There are 3 types of cables:

    1. QWIIC cable

    2. hand made QWIIC to RJ11 cable

    3. RJ45 cable CAT6

    I’ve already tested and seems like cables does not have impact on that. I tried to use really short one (like up to 5 cm).

    Try to move these cables as far away from 230V lines.

    I tried to disable 230V present in electrical cabinet and provide 5V for UniPi from outside source.

    Problem still exists in that case.

    Are the QWICC bus mid-point and end-point shielded somehow? Maybe the spikes are entering there?

    No, I did not shield them.

    How could i do that? I don’t see anything in documentation, but this might be a point.

    Is there a glitch or very small spike on the DC supply line the moment you connect the lamp

    No, i checked that with oscilloscope.

    Try using another 230V power connection point in the house for the lamp and UniPi. Maybe one that is not connected to the same 230V fuse in the fusebox. Maybe a loaded group or bad connection in the in-house wire somewhere?

    I already tried. Always the same problem.

    If you happen to have it, connect a small capacitor across the DC power supply (https://en.wikipedia.org/wiki/Decoupling_capacitor)

    I did not connect that, since there is no peak viable on oscilloscope.

    I have also tried different power-supply and there was still the same issue.

    Is there a ground loop issue? Don’t know about your place but here in the old days in The Netherlands, the 230V NULL was connected directly to GND. If you have a “weak” ground connection a change on the NULL would then impact the GND level and impact your circuit. These days however the NULL is not connected locally to GND anymore. BUT could there be something in your situation?

    Here in Poland we call it TN-C circuit and it’s forbidden (as far as i know) to have such a installation.

    I have TN-S (N cable and PE cable are separate ones).

    I think problem is related to QWIICBus Kit.

    I’ve connected LiDAR / ICM20948 to I2C splitter itself (I’ve complitle bypassed QWIICBus Points) and it was working fine.

    I tried to reproduce the problem and i couldn’t.

    I tried to connect LiDAR to first QWIICBus Point and problem was there.

    I tried to disconnect next QWIICBuses point but problem was still there.

    I’ve exchanged cables for 5cm onces and problem was still there.

    I’ve destroyed 2 [QWIICBus MiddlePoint during this try.[/b]
    Last idea was that maybe [QWIIC EndPoint can’t be used as starting point, so I exchanged it with middle one. And problem was still there.
    Might it be that [QWIICBus Kit is not supposed to work with 5VDC as I2C voltage level by default? I know that you recommended already using 5V, but I totally misunderstood it there. For now I’ve connection like this:
    UniPi 1.1 | QWIICBis EndPoint
    ------------|---------------------------
    5V | 3V3
    GND | GND
    SDA (5V) | SDA
    SCL (5V) | SCL
    I did so, because I can see on [hookup guide that:
    ** **The PCA9615 has two supply voltage rails: VDDA and VDDB. VDDA acts primarily as the I2C-bus side power supply and VDDB primarily is used for the differential side power supply. While the two power supplies have slightly different operating ranges (VDDA supply voltage range: 2.3-5.5V. VDDB supply voltage range: 3.0-5.5V), both the EndPoint and MidPoint default to net both voltages together at 3.3V.** **
    Do you have experiance with QWIICBus Kit?](SparkFun QwiicBus Hookup Guide - SparkFun Learn)](SparkFun QwiicBus Hookup Guide - SparkFun Learn)](https://www.sparkfun.com/products/16988)](https://www.sparkfun.com/products/16988)

    hi

    What a challenge :slight_smile:

    No, I don’t own an SMBUS kit but have been studying the schematics and descriptions and I found them complex.

    In general, it is very easy to be confused about how to power the devices and Qwicc bus .

    The PCA9615 chip has an unbalanced side (where the device is always connected) and a balanced/differential side (where the RJ-45 wire is always connected). The unbalanced is always powered by VCC the balanced/differential side is always powered by VCC-1.

    VCC-1 should have one and only one source. Ideally, that is on the mid-point. In that case, if your device connected to an end-point has its own VCC, make sure to cut the jumper on the endpoint between VCC and VCC-1. If however, your device on the end-point does not have its own power it CAN be powered by the VCC-1 ( e.g. VCC from midpoint), assuming the device can handle that. (5V / 3V3).

    NEVER connect a device supplied VCC on an endpoint/mid-point to VCC-1 if that VCC-1 is already connected somewhere to a power source.

    Always connect a device with the VCC it can handle. That VCC can be provided locally OR from VCC-1. BUT, again, it is EITHER direction, not both !! The SDA/SCL pull-ups are connected to the VCC, unless you cut a separate jumper in the board to not have pull-ups. The latter would only make sense if the connected device already has pull-up resistors.

    You should consider the VCC-1 as the power source for the balanced/differential side of the PCA9615 and it should be supplied from ONE source only. The schematics state by increasing the VCC-1 to 5V, taking into account cutting some jumpers, you get a signal on the RJ45 wire that is ranging between 0v and 5V. Thus less vulnerable to noise. BUT increase to 5V means that if any of your devices connected that is sourcing the power from VCC-1, it needs to be able to handle 5V. The maximum VCC-1 can handle is 6V (according to the PCA9615 datasheet)

    To make things even more complex there is a VCC-2. It is actually a completely (optional) separate power line that can be used to power a local device. On a midpoint, there is a Buck regulator that CAN create a VCC-1 and create VCC, but again you need to handle the jumpers. Now here is where I am confused the Buck regulator output connects with a jumper to VCC-1, but is always connected to 3V3 / VCC mid-point?

    Honestly… the QWIIC bus is modular to a point that it is complex. In my mind, the hookup guide should have usage scenarios to show how to setup and where to cut or connect jumpers.

    Thank you for detailed explanation!

    I’ve modified MiddlePoint to 5V (Breakpoint jumper is OPEN now and PSEL is CLOSED to 1).

    Moreover I’ve noticed a voltage peak on power-supply output, while connecting electrical device to the same circuit from which power-supply is energized from. Seems like this is the real issue there. (see picture below)

    I’ve tried 3 different power-supplies and there is still the same issue:

    1. [Mean Well HDR-15-5

    2. [Phoenix ContactUNO-PS/1AC/ 5DC/ 25W

    3. [S8VK-G01505 OMRON

    Moreover I’ve tried to add [NEF-1-3 filter, but it also did not improve the situation.

    Do you have any tip what i can do to reduce the peaks?](https://www.tme.eu/pl/details/nef-1-3/filtry-przeciwzakloceniowe-pozostale/phoenix-contact/)](https://www.tme.eu/pl/details/s8vk-g01505/zasilacze-na-szyne-din/omron/)](https://www.phoenixcontact.com/online/portal/pl?uri=pxc-oc-itemdetail:pid=2904374&library=plpl&tab=1)](HDR-15-5 Zasilacz na szynę DIN 15W 5V 2.4A - Zasilacze Mean Well)

    My Polskie is not as good as yours… so could not read the specifications.

    Now it looks indeed that the voltage peak is the real issue and thus your circuit is impacted through the power supply. While focus on how to suppress it is actually more interesting to focus on why is that happening in first place? It not normal when you plug in a lamp and surge like this is happening. It is not a single spike, but it starts as a ripple that extinguishes out. There must be some circuit that causes this.

  • What happens if you connect the lamp directly to the wall plug. Nothing else in between! Does that break the communication or cause this spike.

  • Is there some sort of a noise reduction system in the house.Maybe in your extension cord?

  • If you have earth leakage circuit breaker in the house. Is there anything in the specification that could provide a clue ?

  • Do you happen a group in the house that is NOT using an earth leakage circuit breaker? Maybe you can by-pass for test
  • To suppress. I saw you tried that already. Normally a capacity (a small one) can “short circuit” high frequency spikesLook interference filters and articles like : https://www.electronicdesign.com/power- … pply-noise

    Thank you very much for discussion Paul.

    I solved peak problem by using laboratory power supply.

    I also tried with PC power-supply but peak was still about 2V. It’s still too much and QwiicBus did not survive that.

    Topic can be closed!

    And really thanks for discussion. You are awesome person!