I'm working with an ESP32-C3-MINI-1-N4 and need to connect four sensors: an accelerometer, a temperature sensor, and two infrared pulse sensors. Due to space constraints, I only have GPIO 8 and GPIO 9 available. Can I connect all these sensors using I²C? If some sensors share the same I²C address, would an I²C multiplexer be the best solution? Any advice on setup or alternatives would be greatly appreciated!
-
\$\begingroup\$ Had you determined if SDA and SCL could be mapped to GPIO8/9? If you could not change the I2C address a multiplexer is the best solution. \$\endgroup\$– user317139Commented Nov 8 at 22:41
-
\$\begingroup\$ Have you already chosen the sensors? It’s more likely than not that different types will have different adresses, and for the IR pulse sensors, picking one with a programmable address would probably be the simplest. \$\endgroup\$– jcaronCommented Nov 8 at 23:08
-
\$\begingroup\$ Did you note that the N4 variant is not recommended for new designs? \$\endgroup\$– jcaronCommented Nov 8 at 23:13
-
\$\begingroup\$ @Cambriolages i added my schema \$\endgroup\$– achraf achrafCommented Nov 9 at 18:13
-
\$\begingroup\$ @jcaron i added my schema \$\endgroup\$– achraf achrafCommented Nov 9 at 18:13
2 Answers
To resolve multiple I2C target devices with overlapping addresses, you can use I2C multiplexors. Another approach is to use I2C address translator chips, such as the LTC4316. These connect between the main I2C bus and a target device and logically changes the target device's address (as in the master uses a different address but the far-side target sees its own address). This means that you don't need to worry about operating the mux in your software.
Looking at the possible I2C addresses of the devices based upon the net names used in the schematic in the question:
Device | Address (7 bits) | Comment |
---|---|---|
MAX30102 | 1010111 |
Only supports a single fixed address. |
MPU-9255 | 1101000 AD0 = 0 1101001 AD0 = 1 |
Two possible addresses, selected by the AD0 pin. |
APDS-9960 | 0111001 |
Only supports a single fixed address. |
MLX90614 | 1011010 |
Factory default address. The actual address is stored in EEPROM and can be modified. |
Therefore, the above sensors have different I2C addresses and no multiplexing is required.