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?
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.