Electronic – i2C multiplexer to use multiple sensor of the same type

i2cmultiplexer

I would like to hook up multiple sensor of the same type (temperature, pressure and so on). The problem is that each sensor can only have 2 different unique values for the register, so can't put more than 2 on a single I2C bus.

I would like to multiplex the I2C channel; so I can plug more sensor; altho I do not know

  • What kind of breadboard to get (found few store online that has analog multiplexer; is that OK for my case?)

  • What kind of code should I write? Do I have to ping each sensor in a sequential way? is there an example about how to cycle trough various sensor using a multiplexer?

I use an Arduino clone board, called Teensy; but I saw also a nice clone called Trinket pro; they both are programmed via the Arduino programming language; so any example would be really appreciated.

Best Answer

You can use a pair of analog muxes or an I2C mux (e.g. PCA9544A) to select a sensor (or pair of sensors). You can only access one sensor at a time unless they sit on completely separate busses, so what you will need to do is select one bus, read each sensor on that bus, then select the next bus and read the sensors, etc. until all values are read. To switch the mux, you will either use I/O pins (analog mux) or the I2C bus itself (I2C mux). Just make sure that the mux is set correctly before trying to read from the sensors. Two nested for loops would work nicely, the outer loop will set the mux, and then the inner loop would acces each sensor on the segment.