multiplexer/ decoder

hi

i'm supposed to work with 20 sensors and they are all the same type TCS34725 color and light sensor

my question is Do i need a multiplexer/ decoder for the communications between sensors and arduino mega ?

Not on the sensors themselves but on the I2C bus as all the sensors will have the same address. So you need to switch the bus to each sensor, that means two signals per sensor.

From the I2C Bus Spec:
"3.1.1 SDA and SCL signals
Both SDA and SCL are bidirectional lines, connected to a positive supply voltage via a
current-source or pull-up resistor (see Figure 3). When the bus is free, both lines are
HIGH. The output stages of devices connected to the bus must have an open-drain or
open-collector to perform the wired-AND function. Data on the I2C-bus can be transferred
at rates of up to 100 kbit/s in the Standard-mode, up to 400 kbit/s in the Fast-mode, up to
1 Mbit/s in Fast-mode Plus, or up to 3.4 Mbit/s in the High-speed mode. The bus
capacitance limits the number of interfaces connected to the bus.

For a single master application, the master’s SCL output can be a push-pull driver design
if there are no devices on the bus which would stretch the clock."

I was looking at the TCS34725FN spec, and couldn't quickly determine if clock stretching was implemented or not.
http://ams.com/eng/content/download/319364/1117183/182615
The response times looked really long tho, like you start a sample request and then wait for an interrupt to tell you it is done. So maybe with some I2C mux chips you could start several off in a sequence, then as interrupts come in go back thru in the same sequence and read them.
Here's a 4-channel I2C mux chip, there may be others as well.

It supports 8 address locations, so you can use 5 chips for the 20 devices. You can use the address that corresponds to A0/A1/A2 low; tie A1 & A2 low, and use a shift register to control which device has A0 low and the other 4 high so that only 1 device responds to the address for A0/A1/A2 low, the other four will see A0 high/A1 low/A2 low and not respond.

Similar to CrossRoads' suggestion above, these breakout boards support 8-way multiplexing, so you would only need 3 of them for 20 sensors.
s-l300 (1).jpg

The other chip provides muxing for the interrupt line as well, which looks to be needed for the TCS34725FN chips.
Maybe ganging all the INTs together could be done, maybe not. I'd go with the flexibility of having it and then deciding to not use it later, vs finding out it was needed and then not having access to it.

Sounds like the interrupts are needed only if you want the sensor to alert when the reading moves outside a certain range. If you just want to regularly take readings, it can probably done just by timing, leaving the interrupt pins unconnected. Then you can get the mcu to check the range of each sensor and take action as appropriate.

Also, sounds like there are models that might be available with two different addresses (0x29 and 0x39). If you can get half your sensors with different addresses, you can place two sensors on each bus, reducing the number of multiplexers required.

sounds like there are models that might be available with two different addresses (0x29 and 0x39).

If you have that then there is no need for any multiplexing of the bus lines. Simply connect the address line of each to an I/O pin and hold all but the one you want to read high. The read the lower address. You can use something like the 74LS138 to save on I/O pins.

Grumpy_Mike:
If you have that then there is no need for any multiplexing of the bus lines. Simply connect the address line of each to an I/O pin and hold all but the one you want to read high. The read the lower address. You can use something like the 74LS138 to save on I/O pins.

Mike, there is no externally accessible address line. Page 3 of the data sheet says they can be purchased from the manufacturer with two different addresses (slightly different model numbers). It's probably a long shot that the alternative model number is available (unless you want to buy a million of them).

Sorry I thought you were talking about using another sensor, one with an external address line.