0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ The electronics part of this question appears to be a duplicate, i.e. similar questions have been asked and answered before. See electronics.stackexchange.com/q/130235/9006, and especially this data sheet ti.com/lit/an/scaa106/scaa106.pdf figure 5 and 6. You don't need an analogue multiplexer. \$\endgroup\$ – gbulmer Oct 9 '14 at 1:21
  • \$\begingroup\$ Thanks; but the question seems related, not duplicate. There the question is how to add multiple sensor of a specific type. In my case; I am aware of how to put multiple sensor changing the registers; but I was asking for a suggestion about the multiplexer and the code to write for it. \$\endgroup\$ – rataplan Oct 9 '14 at 1:25
  • \$\begingroup\$ The electronic design part seems IDENTICAL to me; how to use multiple sensors with the same I2C address. Folks here might help with code, but a purely software question may get a better answer at the Arduino stack exchange, Arduino.cc, or stackoverflow sites. \$\endgroup\$ – gbulmer Oct 9 '14 at 1:30
2
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.