Electronic – How to connect non-I2C devices to an I2C bus

expandergpioi2craspberry pi

I'm quite new to electronics and just trying to do my first Raspberry Pi based system: one diode, one pressure sensor and LCD 1602 with keypad shield (the one for an Arduino board). The way I'd like to connect all the devices is using I2C (the Raspberry Pi doesn't have much GPIO).

And here comes the question: How can I possibly connect non-I2C devices to the I2C bus? I heard about different expanders, like the MCP23017, will that solve the problem?

Best Answer

It is possible that the question represents a misunderstanding or miscommunication of the kind of connection desired: Not something to be connected to the I2C bus itself, but to be controlled via some intermediary I2C to GPIO device, which further is connected on the I2C bus.

The idea of non-I2C devices being connected to an I2C bus is meaningless. The I2C protocol has specific requirements, for the I2C master to address the slave device, and for communicating data in either direction.

The LCD mentioned in the question, for instance, works on a different set of communication protocols, using multiple GPIO pins, and (from the description) most likely does not recognize I2C. There are however I2C LCD modules available, which incorporate I2C slave functionality on board - either through an LCD controller or a dedicated microcontroller with I2C slave communication code. Instead of the basic LCD module mentioned, such an I2C display module would be required for use on an I2C bus.

I2C bus expanders cannot magically create I2C functionality on a connected device. What I2C bus expanders can do, however, is provide additional GPIO pins, which are then controlled by code from the Raspberry Pi or microcontroller through the expander, which itself responds to I2C commands.

Perhaps that is what is desired - in which case, sure, it will work but not as described: A GPIO-driven device such as the LCD module or an LED can be wired up to the expander's GPIO pins, and the expander is the device that is connected to the I2C bus.