2 sensors ( I2C type) for One Arduino

KeithWalker

Joined Jul 10, 2017
1,222
Hi everone ,

I am looking for a way to use two I2C sensors with the same I2C address of the same I2C port.

Regards,
It doesn't work that way. You have three choices:
1. You find a way to change one of the addresses
2. You get a new sensor with a different address.
3. You use a different interface.
Regards,
Keith
 

Papabravo

Joined Feb 24, 2006
14,420
If the two lines SCL and SDA are all you have then you'll be looking for a long time to make this happen. Where do you guys come up with stuff like this?
Incroyable!
 

dendad

Joined Feb 20, 2016
3,602
You can produce a second I2C port by driving the SCL and SDA lines to each sensor via an analog mux and select the sensor that way. Or bit bang another I2C port. Or a second Arduino.
But as mentioned above, the sensors need to have different addresses, or I2C ports.
 

Thread Starter

Tarek1266

Joined Oct 18, 2019
33
You can produce a second I2C port by driving the SCL and SDA lines to each sensor via an analog mux and select the sensor that way. Or bit bang another I2C port. Or a second Arduino.
But as mentioned above, the sensors need to have different addresses, or I2C ports.
Can you provide me with more details about the mux solution ?
 

dendad

Joined Feb 20, 2016
3,602
Have a look at something like a CD4052 dual analog multiplexer.

Connect X and Y to SDA and SCL on the Arduino.
X1 and Y1 to sensor 1 SDA and SCL.
X2 and Y2 to sensor 2 SDA and SCL.
A to a port pin used to select the sensor, and B to 0V for just 2 sensors, or another port pin for 4 sensors.
INH to 0V
VEE and VSS to 0V
VDD to 5V

make sure both sensors have pullup resistors.

https://www.ti.com/lit/ds/symlink/cd4051b.pdf
 

jangliss

Joined Mar 15, 2020
3

Thread Starter

Tarek1266

Joined Oct 18, 2019
33
Have a look at something like a CD4052 dual analog multiplexer.

Connect X and Y to SDA and SCL on the Arduino.
X1 and Y1 to sensor 1 SDA and SCL.
X2 and Y2 to sensor 2 SDA and SCL.
A to a port pin used to select the sensor, and B to 0V for just 2 sensors, or another port pin for 4 sensors.
INH to 0V
VEE and VSS to 0V
VDD to 5V

make sure both sensors have pullup resistors.

https://www.ti.com/lit/ds/symlink/cd4051b.pdf
What is the connection of the pullup resistors ?
 
For one sensor keep the SDA and SCL the way you have it... for the other sensor swap the SDA and SCL. in software talking between the two just reassign the SDA or SCL depending on which sensor you want to talk to.

Note: This will only work if you have two sensors with the same address on the I2C buss. We did this all the time over the years when I was an employee at Parallax Inc. ... i.e. a p;opular I2C memory expansion card utilized this method
 

Thread Starter

Tarek1266

Joined Oct 18, 2019
33
For one sensor keep the SDA and SCL the way you have it... for the other sensor swap the SDA and SCL. in software talking between the two just reassign the SDA or SCL depending on which sensor you want to talk to.

Note: This will only work if you have two sensors with the same address on the I2C buss. We did this all the time over the years when I was an employee at Parallax Inc. ... i.e. a p;opular I2C memory expansion card utilized this method
Can you clarify more ?
 

dendad

Joined Feb 20, 2016
3,602
For one sensor keep the SDA and SCL the way you have it... for the other sensor swap the SDA and SCL. in software talking between the two just reassign the SDA or SCL depending on which sensor you want to talk to.
That is very clever!
I'm not sure how hard it is to do with the Arduino. Probably have to bit bang it, not use the inbuilt I2C.
Maybe someone else can clarify.
 

djsfantasi

Joined Apr 11, 2010
6,821
What are the sensors you are using?
Why can’t you use individual sensor addresses? I’ve never seen this scenario. Sensor addresses are always customizable that I have seen.
 
Top