Looking at the arduino, there are a pair of SDA and SCL pins above the AREF pin and also another pair at A4 and A5 pin. Why are there two? Are they both necessary for I2C communication or can I force the arduino to use only one of the two pairs?
They are the same pins in parallel. You can use them interchangeably.
Why are there two?
For convenience, I guess.
The UNO has it on A4/A5 but Mega on different pins (20/21), depending on used MCU. Arduinos since Rev3 have extra pins for SCL/SDA to be at same place for shields regardless of board type. I2C is frequently used bus.
Thanks, Budvar10. I assumed an Uno as the board was unspecified. My bad.
So, can we use both the pair of pins(on uno R3) simultaneously? I mean for two different modules. Actually I want to use the 0.96" OLED and a gyro simultaneously.
can we use both the pair of pins(on uno R3) simultaneously?
I don't see why not. Electrically they are the same (in parallel).