Multiplexing I2C. Both data and clock?

Hello

I need to read 5x VEML6040 colour sensors, but they have a fixed I2C address of 0x10.

Do I need to switch both the I2C lines through (individual) 74HC4051's, or can I 'get away' with only switching the data line (SDA) and joinging all the clocks (SCL)?

Data reading is slow... so no worries about speed.

Just would save some PCB space

Yes, SCL and SDA are bidirectional.

I suggest you use of an dedicated I2C multiplexer.

Thank you... a searching I go then...

Here:

see it used on these fora quite a bit.

a7

They also make a four channel version:

https://www.adafruit.com/product/5663

Thanks all... probably go with the TCA9548A.... as I may need to read up to 5 sensors.
I will look for the IC and add it to my PCB design

There are SO MANY IC packages types..... lost count how many times i have made a PCB, only to find I used the wrong footprint (Even with the help of SnapEDA).

SOP-24. What footprint is that? Is that the same as TTSOP-24?

The data sheet from the device manufacturer that you select will have all the information you need about the package that you select.

I have that... but the supplier page just says SOP-24. I'll take a risk

The manufacturer’s part number contains the package information. Rely on that.
If the supplier cannot be relied upon to supply the part number that you order then you could consider getting a reliable supplier.

It is a 3.3V sensor, which Arduino processor do you use ?
The TCA9548A can do level shifting at the same time.

If your processor runs at 3.3V, then you can connect SCL to everything and only multiplex SDA.

When you have 1 main I2C bus and 5 sub I2C buses, then you have a total of 6 I2C buses. Each part needs pullup resistors. For the TCA9548A that are 12 resistors.
When a sub I2C bus is not used, then it is important that SDA and SCL stay high (idle), pulled up with a resistor.

Don't worry about that right now. You need to build a prototype, test it, fix it, test it, fix it, test it, fix it... until it works. Only then do you design a PCB. That's the way it's done by professionals. Amateurs design the PCB, it doesn't work, it goes to landfill, they have another go, it also goes to landfill, they give up.

So buy that breakout that @alto777 suggested, several breadboards... you get the idea.

12 resistors? Can you not just hold the actual live I2C bus (on the 3.3v Nano) high before the switch?

Didn't realise all the devices would need their own individual pull-ups. This is going to start getting too big for the small space on the PCB (yes I know...prototype first, I always do that).

So... I can just switch the SDA lines then. In which case, that would halve the amount of pullups instantly. I have switched I2C before using a 74HC4051 when in a pinch.

I needed to run 8x identical OLED screens on one I2C bus. Just can't remember what I switched, but I know I didn't have 16x pull-up resistors!

But... I think the sensor datasheet shows 1k pull-ups as default

Those I2C multiplexers turn on and off the sub I2C buses with mosfets. They are really disconnected if not used. The same for the 4051. You need pullups everywhere.

If the sensors have a internal pullup, that would be great.
Maybe the processor can turn on internal pullups.

No, they are the bare sensors going directly on the reverse of the board.

I have bought a pack of 10 sensors, as that was the min order. I will design my PCB, but before having it made, I will make some smaller 'breakout' PCB's with my intended circuit on it.
I can then breadboard that and make sure it works.

Can we go back to the original question?

If a sensor sees SCL switching, but SDA is constant high, what does it do? Is it obligated to send a nak, or whatever, on SCL?

If not, then maybe you could just switch the SDA line. It might be worth testing this on the OP's sensors. If it works, you would only need one set of pullup resistors, and only one 4051, provided you have enough pins for the three output selector pins.

Every I2C device is waiting for a START condition, and then reads the bits to check if it is its address. So only after the START condition, the clock pulses are used to read the bits.
The START condition begins when SDA drops from high to low. As long as SDA stays high, the SCL can be anything.

For "dumb" sensors, the SCL is not bidirectional, and the SCL clock signal is put on the I2C bus by the Master. Only if the sensor has a processor inside that needs to keep the SCL low for clock pulse stretching, then it is a bidirectional signal.

Page 8 of the official I2C standard: https://www.nxp.com/docs/en/user-guide/UM10204.pdf:
"For a single controller application, the controller’s SCL output can be a push-pull driver
design if there are no devices on the bus which would stretch the clock".

The common OLED screen modules generally have pullup resistors, so the only problem would be too low a resistance from all those resistors on a common bus. The OLED displays also typically have an input to select between two different I2C addresses, which allows you to switch between displays by dynamically changing the I2C address.
That technique of course will not work with the VEML6040.

I'm not familiar with designing I2C circuitry, so maybe someone can comment on whether a multi-resistor array in an IC package is usable for the pullup resistors, that would take less space on a pc board than individual resistors.

Thanks for all the help...

The sensor datasheet shows basically a couple of pull-ups on the I2C and that is it.

The breakout board for this device appears to have more components but I don't know what they all are...

https://vi.aliexpress.com/item/32954166250.html?gatewayAdapt=glo2vnm

I am guessing they have added a 5v/3.3v reg and a mosfet to switch on an onboard white led for local illumination.

I do have pins available for addressing a switch, so the TCA9548A is probably the tidiest solution, if I can find it for a reasonable price (I have a whole pile of 74CD4051's here already).

You only need to MUX the SDA line.
Yon can fan out the SCL to all 5 devices with only one pull-up