2 components both having SCL and SDA

Hello i have 2 components, a LCD 1602 with an I2C module and a HMC5883L accelerometer module. Both modules require a SCL and SDA connection, and i need to use them on an arduino mega where there is only 1 set of SCL and SDA port. How can i solve this issue?

You connect all I2C modules to the common SCL/SDA bus and to power and GND.

1 Like

Each device should have a configurable set of address jumpers. Look at whatever documentation you can get for the two devices.

1 Like

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for advice on (nor for problems with) your project.

Ideally, the two devices will come from the factory with different default addresses. In that case, you won't have to mess with jumpers to change the addresses. But you do need to know what the addresses are. There are sketches you can use that scan all possible addresses and tell you which addresses have devices there. You would run it with one device attached at a time. Here's one:

https://create.arduino.cc/projecthub/abdularbi17/how-to-scan-i2c-address-in-arduino-eaadda

One thing you have to be a bit careful about is if both devices have pullup resistors on SDA and SCL. You only need one set of pullups, and having two sets may pull too much current when the line tries to go low.

1 Like

The Mega has actually two SDA and two SCL pins. They are both connected to the I2C bus of the microcontroller.

So if it's about physically connecting, you can use those for the second device; check the pins next to the TX1/RX1 pins.

Yes i saw that, 1 set on the top and the common one near the Rx and Tx

But concerning the programming will that change anything or can i simply just connect each one to its specific set?
I mean do i have to individually declare each one?

I2C is a bus. Both sets of pins on the Mega are on the same bus. So device 1 on one set of pins and device 2 on the other or vice versa does not make a difference.

Some microcontrollers have two seperate I2C buses, but that does not apply to the Mega.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.