Connecting VEML6040 to tca9548a multiplexer

Hi everyone I wanted to connect multiple color sensors to raspberry pi 4 using the tca9548A multiplexer but I’m having a lot of problems programing it.
The documentation I found is not as helpful as it is telling me to import a library called board.
I was wondering if anyone can help me out or share a code sample I would be really great full.

1 Like

Hi Reza,

Welcome :slight_smile:

I’d try out the Sparkfun example code if you haven’t already:
https://learn.sparkfun.com/tutorials/qwiic-mux-hookup-guide#python-package-overview

1 Like

Hi Liam thank you for the guid I just ran the code and it works I can see the sensors and list them in the code.
However I have another problem as well I have 2 colors sensors the ones I mentioned before their address is 0x10 and I don’t know how to configure the new code.
Like how can I for example tell the code where to look and after that how should I use the functions as normal?


I attached the photo here.

So I tried to change the bus or the address just to see what happens they all came up with an error

This is what I get when I list them the sensors are on channel 0 and 1

1 Like

Hi Reza,

Try enabling one of two channels, removing a PiicoDev initialisation then looping through each of the mux channels like this:

for i in range(0,1):
    colour_output[i] = colour_sensor.readRGB()
1 Like

Liam you helped me big time thank you.

I think what I didn’t understand was how multiplexer works. So I’ll say it for others as well.

Basically based on what I found out you can think of multiplexer as a gate in my case I had 2 sensors same address so We use multiplexer to disable all the channels / gates except one that we need and to use the other one we disable the previous channel and enable the one that we need to use.

Hopefully the analogy helps someone like me to understand.
I could still be wrong though so feel free to educate me.
Thank you Liam

3 Likes

Hi Reza,

No worries at all! Yeah muxes are confusing, the gate analogy is a really good one.

I do very much like the idea of putting channels in as an argument

1 Like

Hi, is this video of any help?