Multiple I2C devices at same address ....

My latest project requires 2 i2c "wire" connections to two identical devices that have the same address, and can't be changed.

Can I instantiate 2 "wire" interfaces, using 4 of the Nano I/O ports (2 for each, obviously), or do I need to use an i2c expansion board, such as the HW-617 using the TCA9548A chip.

The two interfaces will never be active at the same time...

TIA

I think I have found my answer, to switch or direct the SDA to each device, and since I'm already including a TCA4468 to multiplex 2 IR transmissions to 2 sky boxes, then I can use the other 2 free channels to multiplex the SDA lines to the 2 devices.

I've also read that you can leave the SCL connected to both, and if the unswitched one doesn't receive any data it doesn't complain.

Anyone have anything to add to that, possible problems etc. ?

I've also read that you can leave the SCL connected to both, and if the unswitched one doesn't receive any data it doesn't complain.

Anyone have anything to add to that

Just don't believe everything you read.

Grumpy_Mike:
Just don't believe everything you read.

Aaaargghhhh ! So this causes a problem ?

Think I'll breadboard it before doing PCB design, and if I need to gate the SCL as well I can use another TC4468

You can use multiple instances of software ("bit bang") I2C -- need two pins for each instance.

I would switch SCL as the devices should ignore activity on SDA unless SCL is also active for them.

Or use an Arduino variant with more than one Wire interface.

Or use software Wire.

Or buy a different device.

Maybe post a link to the datasheet?
And not guess?

Hi,
I have had this problem and found this solution with works very well.
It uses diode switching of the SCL (clock) line.
I2CDual.jpg

This is the code I was using on two VCNL4010 distance sensors.

#include <Wire.h>
#include "Adafruit_VCNL4010.h"

Adafruit_VCNL4010 vcnl;

int detectRightPin = 8;
int detectLeftPin = 9;
bool Select = true;

void setup()
{
  Serial.begin(115200);
  Serial.println("========================VCNL4010TEST_TGIMD_1=====================");
  Serial.println("======================UNO========================================");
  Serial.println("VCNL4010 test");
  pinMode(detectRightPin, OUTPUT);
  pinMode(detectLeftPin, OUTPUT);
  //Select Left Sensor to initialise Sensor and I2C Library
  digitalWrite(detectRightPin, LOW);
  digitalWrite(detectLeftPin, HIGH);
  delay(250);
  if (! vcnl.begin()) {
    Serial.println("Left Sensor not found :(");
    while (1);
  }
  Serial.println("Left Found VCNL4010");
  //Select Right Sensor to initialise Sensor and I2C Library
  digitalWrite(detectLeftPin, LOW);
  digitalWrite(detectRightPin, HIGH);
  delay(250);
  if (! vcnl.begin()) {
    Serial.println("Right Sensor not found :(");
    while (1);
  }
  Serial.println("Right Found VCNL4010");
}

void loop()
{
  if (Select == true)
  { // Read Left Sensor
    digitalWrite(detectRightPin, LOW);
    digitalWrite(detectLeftPin, HIGH);
    Serial.print("Left   Ambient: ");
    Serial.print(vcnl.readAmbient());
    Serial.print("\tProximity: ");
    Serial.print(vcnl.readProximity());
    Select = false;
  }
  else
  { // Read Right Sensor
    digitalWrite(detectLeftPin, LOW);
    digitalWrite(detectRightPin, HIGH);
    Serial.print("  \t\tRight   Ambient: ");
    Serial.print(vcnl.readAmbient());
    Serial.print("\tProximity: ");
    Serial.println(vcnl.readProximity());
    Select = true;
  }
}

Hope this helps…

Tom… :slight_smile:

Grumpy_Mike:
Just don't believe everything you read.

Why do you think disconnecting SDA is wrong and SCL is OK? I would expect the device with SCL disconnected will see a lot of START and STOP conditions which may confuse it. OTOH with SDA disconnected transitions on SCL will be ignored since the disconnected device does not see the START condition...

Don’t start.

Hi,
As long as the I2C device doesn't see a clock TRANSITION it doesn't read the I2C SDA.

Tom... :slight_smile:

TomGeorge:
Hi,
As long as the I2C device doesn’t see a clock TRANSITION it doesn’t read the I2C SDA.

Tom… :slight_smile:

No, this is not true. START and STOP condition is defined as SDA transition while SCL is HIGH. So I2C device samples SDA line while SCL is HIGH continuously.
In your example it does not matter - the “deselected” device has SCL LOW. In other implementation if the SCL line were kept HIGH deselected device would see series of START and STOP conditions.
IIRC STOP condition should not follow directly a START condition but I may be wrong. OTOH I am not sure if it is allowed toggle clock without previous START.

EDIT: @Grumpy_Mike - I do NOT want to start an argument. In fact I did not notice it was your post until I started typing my original question. I really want to know why do you think keeping SCL connected is wrong. Or did you mean the comment more general? Such as “despite this particular advice is not bad don’t blindly follow everything you read unless you know what you are doing”?

TomGeorge:
Hi,
I have had this problem and found this solution with works very well.
It uses diode switching of the SCL (clock) line.
I2CDual.jpg

Hope this helps…

Tom… :slight_smile:

Hi Tom, can I ask what drawing package you use to make your schematics, looking for something for my circuits as it is tedious to do it in Excel. TIA

Hi,
I used a CAD program called ExpressPCB, it does schematics and PCB, but not a gerber for PCB manufacture, it does a file for the PCB group that supplies ExpressPCB for free.

I use it for schematics because it is easy to use and make your own components.
This page explains some of it and has the download button.

https://www.expresspcb.com/expresspcb/

Tom... :slight_smile: