which pins should i take for i2c on arduino uno

27,124

Solution 1

Look at the complete diagram: enter image description here http://pighixxx.com/unov3pdf.pdf

SDA and SCL pins are PC4 and PC5 pins of the microcontroller (pin number 4 and 5 of port C). Pins A4 and A5 are also PC4 and PC5. This means they are connected together.

So you can use any of these, it does not matter.

Solution 2

The earlier versions of the Uno did not have the separate SDA/SCL pins. Then as they started making other boards (such as the Leonardo) there was a problem that the Leonardo SDA/SCL pins were not A4/A5 (they are D2/D3).

To make it easier to make shields which use I2C the manufacturer added the SDA/SCL pins in a known location. For both boards they are connected to the correct pins for that board.

A similar remark applies to the later versions of the Mega2560 board.

You can use either pins: the ones marked SDA/SCL or the appropriate pins for the board to hand. They are connected together so it doesn't matter which ones you choose.


Partial schematic from the Uno showing the two sets of pins are on the same "net" which means the pins are internally connected.

SDA and SCL on the Uno

Share:
27,124
Bob5421
Author by

Bob5421

Updated on July 09, 2022

Comments

  • Bob5421
    Bob5421 almost 2 years

    I am trying to create an i2c communication bus with an arduino UNO.

    i2c requires SDA and SDL pins. I see on arduino UNO there is twice SDA and SDL:

    The 2 first pins side to usb connector are SDA/SCL according to documentation.

    And the documentation says A4 and A5 pins can also be SDA/SCL

    So i do not understand which pins i can use.

    enter image description here

    Thanks

  • Bob5421
    Bob5421 over 7 years
    Why are they connected ?
  • Bob5421
    Bob5421 over 7 years
    For example can i work with analog IN A4/A5 if i work with SDA/SCL on pins 27-28 at the same time ?
  • Tom
    Tom over 7 years
    I don't know why they are connected. Maybe to ease design of Arduino Shields. You cannot use Analog IN and SDA/ADL at the same time. The idea is that Microcontrollers (MCU) have many peripherals and features (ADC, DAC, I2C, SPI, UART, USB, Timers, etc.). They have much more than available pins on their package. Thus several functions are mapped to each pin. You select the function when you initialize the pin. The Arduino code encapsulate all that, so it is difficult to see. But basically if you would like to change the feature you use (ADC/I2C), you have to re-initialize the pin.