1

I have 2 VL6180X Distance Sensors properly connected to a TCA9548A Multiplexer, however it only recognizes the Multiplexer itself and not the 2 sensors as you can see with the 0x70. Is there any way to configure the i2c adresses?

i2cdetect -y 1

gives me the following output

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- -- 

Ofc, I did already search the web to find a solution for it:

I installed

sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools

I enabled i2c in the kernel (https://raspberrypi.stackexchange.com/questions/66145/raspberry-pi-3-not-detecting-i2c-device)

Added everything to config.txt as in here: I2C not detecting ? issues in hardware or any other?

Luca Ceresoli
  • 1,591
  • 8
  • 19
hux0
  • 207
  • 1
  • 4
  • 17
  • You have to enable I2C multiplexer *driver* in the kernel followed by enabling drivers for your sensors. If there is no driver you have to write one. – 0andriy Feb 12 '20 at 20:21

2 Answers2

3

In order to have the VL6180X properly instantiated behind a mux in Linux you should describe them in device tree. Have a look at the I2C MUX documentation.

Thus you should describe the whole setup (I2C mux + 2x VL6180X) like this:

&i2c1 { // the SoC bus controller
    mux@70 {
        compatible = "nxp,pca9548";
        reg = <0x70>;
        #address-cells = <1>;
        #size-cells = <0>;

        i2c@3 {
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <3>;

            gpio1: gpio@29 {
                compatible = "st,vl6180";
                reg = <0x29>;
            };
        };

        i2c@4 {
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <4>;

            gpio1: gpio@29 {
                compatible = "st,vl6180";
                reg = <0x29>;
            };
        };
    };
};

This will instantiate two new busses (list them with i2cdetect -l) and one vl6180 sensor will appear under each of them and be described as regular IIO devices.

The above code is a simple mix of device tree binding documentation for i2c-mux and for the VL6180X sensor, available in the kernel sources.

Luca Ceresoli
  • 1,591
  • 8
  • 19
1

Luca's answer is better than this, though this should still work.

It doesn't work like that. You can't "see" the attached devices through the multiplexer.

Instead, you open the multiplexer and write a "control byte" to it, to tell it which device it should forward the following data to.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • okay, good to know that. thanks for your help! how do I send a control byte? do you have a code snippet example? – hux0 Feb 12 '20 at 16:15
  • Better than that, there's a little tutorial here... https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/wiring-and-test – Mark Setchell Feb 12 '20 at 16:17