45
\$\begingroup\$

I want to add a real time clock module into my little project. I want to display both time and date on my existing i2c 2x16 LCD module.

Both i2c-interface real time clock module and 2x16 LCD module use the same pin A4 (SDA) and A5 (SCL) on Arduino Uno. After hours of searching on the net the i2c bus can actually take many serial devices. This is possible because each device has its own unique address.

My question is how to physically wire the two i2c-interface devices into a single A4 and A5? Thanks.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Short answer: Wire them in parallel. Tie the SDAs together and connect to A4, and the SCLs to A5. Then of course there is the pull-up issue that sometimes helps. \$\endgroup\$
    – SDsolar
    Commented Mar 23, 2017 at 6:20

6 Answers 6

40
\$\begingroup\$

Some folks are having a hard time visualizing things connected together, so here's a picture:

(Serving suggestion)

schematic

simulate this circuit – Schematic created using CircuitLab I2C is a bus, so like-named signals are connected together. The addressing scheme allows the microcontroller to select which device it's talking to. On the Arduino, the 10kΩ pull-up resistors go to VDD (Usually +5V or +3.3V).

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Hi, this may be very basic but I am new to electronics and landed this page from google search , what uC refers to ? \$\endgroup\$ Commented Nov 30, 2016 at 7:06
  • \$\begingroup\$ I believe the reference is to any uC, as the connection scheme should be the same, unless noted otherwise. \$\endgroup\$ Commented Jan 5, 2017 at 1:29
  • 1
    \$\begingroup\$ uC can be an Arduino. SDA is pin A4 and SCL is pin A5. \$\endgroup\$
    – SDsolar
    Commented Mar 23, 2017 at 6:21
  • 19
    \$\begingroup\$ @Ciastopiekarz, μC is short for "microcontroller." The greek letter μ is the abbreviation for micro. Because μ looks like u, lots of people just write "uC". \$\endgroup\$ Commented Jul 23, 2017 at 1:17
  • \$\begingroup\$ I2C is a 2-wire "shared" serial bus that means that you connect all the SCL clock lines together and all the SDA data together by wires or traces. Electrically, this is okay because each I2C chip added on the bus has open-collector input/output I/O pins that allow being wired together. At least 1 I2C pull-up resistor is required for each of the SCL or SDA lines so the signal can switch hi/low fully. Typically, 2.2K to 4.7K ohms are used but 10K may work, too. \$\endgroup\$ Commented Sep 23, 2020 at 22:46
13
\$\begingroup\$

For I2C, if all the target (called "slave" prior to the 2021 standard) devices have different device addresses, all of the SDA pins should be connected together, and all of the SCL pins should be connected together. It's as simple as that.

Naturally, you should also include pull-up resistors on both lines, as required for I2C. How to choose the resistor values has been discussed here before.

\$\endgroup\$
7
  • \$\begingroup\$ I've found that as long as one of the devices is the DS3231 RTC then no external pullups are required. \$\endgroup\$
    – SDsolar
    Commented Mar 22, 2017 at 21:15
  • 3
    \$\begingroup\$ @SDsolar, that probably means the DS3231 has internal pull-ups, so by using that device, you are providing pull-ups for the bus. That's not necessarily a good thing, because it limits your freedom to adjust the pull up resistance depending on the number of devices on the bus. \$\endgroup\$
    – The Photon
    Commented Mar 22, 2017 at 21:45
  • \$\begingroup\$ My thoughts exactly. Adding external pullups would be in parallel with whatever is in the DS3231, and so might end up not being enough for I2C to be happy. \$\endgroup\$
    – SDsolar
    Commented Mar 23, 2017 at 5:49
  • 1
    \$\begingroup\$ @SDsolar, What does this have to do with OP's question or my answer? This is not a general discussion site. If you want to just talk about stuff, you can join our chat room. \$\endgroup\$
    – The Photon
    Commented Mar 23, 2017 at 15:43
  • \$\begingroup\$ @CATboardBETA - Hi, FYI I'm reversing your last edit here, as (a) the I2C terms you used are not the official new ones, and (b) In any case, we are working on a plan for the whole site about how to handle the changes to I2C terminology. That plan will apply to everyone - so we can't have individual members going around editing that I2C terminology, until that discussion has happened on Meta. Therefore please do not make any more edits for I2C terminology until after that discussion. (That post was planned to happen sooner on Meta, but it's been interrupted by other moderation work.) \$\endgroup\$
    – SamGibson
    Commented Jan 13, 2022 at 6:33
3
\$\begingroup\$

Connect two pins A4-sda to A5-scl(on both board uno-uno) and connect resistor from 5v from each corresponding sda-scl lines.

enter image description here

\$\endgroup\$
0
2
\$\begingroup\$

Another thing to keep in mind is as the number of devices grows, the capacitance of the clock and data lines will increase. At a certain point, the C component increase will affect the rise times of your clock. Unless you are clock stretching, you can make the clock strong drive or put a stronger pull-up on it to avoid this.

\$\endgroup\$
4
  • \$\begingroup\$ Not really. At all times the capacitance affects the rise time. So it does not start affecting the rise time until after certain point. Stronger clock drive does not affect rise time on an open collector bus, only the pull-ups. Clock stretching is rarely used and even if it is it typically is done after each byte, not each bit, so it does not help. \$\endgroup\$
    – Justme
    Commented Aug 18, 2023 at 16:54
  • \$\begingroup\$ A push-pull driver on the SCL line of an I2C single master bus would not result in a faster rise time? \$\endgroup\$
    – cplusruss
    Commented Sep 6, 2023 at 17:19
  • \$\begingroup\$ It would, but you are not supposed to have a push-pull driver on the SCL line as then it is not an open collector bus any more. Because chips can use clock stretching. And even if you do use a push-pull driver on SCL, there is not much benefit if SDA still has long rise time. \$\endgroup\$
    – Justme
    Commented Sep 6, 2023 at 17:39
  • \$\begingroup\$ Yeah, good point. Doesn't really matter if SDA has a long rise time. \$\endgroup\$
    – cplusruss
    Commented Sep 6, 2023 at 18:47
1
\$\begingroup\$

I2C is a data transfer protocol developed by Philips. Also known as two-wire interface since it uses two wires for communication. SCL-Serial Clock Line. SDL-Serial Data Line. So you need to connect corresponding pins of the i2c devices be it an eeprom or lcd to SCL and SDL pins of micro controller you are using with a pullup resistor to VDD. Since it is an addresses protocol having 7-bit address for each device connected you can address upto 2^7 different devices. But normally I2C address of a slave device is predefined with some bits to be hardwired by the developer. This helps in connecting same type of devices with different hardwired address part on the same bus.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ All true, but it sucks if you want more than one, like the BH1750 light-intensity unit. I want 4 of them and don't want to deal with I2C dual-bus switching.. Also, some devices like the DS3231 have internal pullups so any external pullups are in parallel with them. \$\endgroup\$
    – SDsolar
    Commented Mar 23, 2017 at 6:14
1
\$\begingroup\$

Also you should check the pull up resistors. If you use already made boards, not only the chip, that boards usually have pull up resistors on board between buss and vcc. So when you connect every thing in parallel, the resistors are also in parallel, so total resistor value drop and your communication may fail.

\$\endgroup\$

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