UNO R3 (sda-scl and pins 4-5)

Hello everyone.
Can I use sda-scl pins for an lcd and pins 4 and 5 as buttons or sensors, in the same time?

Tilemachos:
Hello everyone.
Can I use sda-scl pins for an lcd and pins 4 and 5 as buttons or sensors, in the same time?

on a Uno type board SDA & SCL are on analog input pins A4 and A5. If you are going to use the I2C functions then you must not use those same pins for buttons and sensors.

Lefty

Thank you Lefty.
So why is there also sda/scl pins in R3?

They're just broken out and labeled as SCL/SDA. It's still the same A4 and A5 pins. They brought out the TWI pins next to the AREF pin for a reason. Read the documentation online to understand why.

Tilemachos:
So why is there also sda/scl pins in R3?

The ATMega328 used on the Uno uses A4 & A5 for I2C, so for the Uno they're the same pins.

On the Leonardo, however, the ATMega32U4 uses pins D2 and D3 for I2C. The Due also uses something other than A4/A5.

If a shield needs I2C connectivity and uses A4/A5 it will only work with a Uno (and the older 328/168 boards). If a shield uses the SCL/SDA pins, however, it should work with all the Arduinos (except the old ones, which don't have those pins)

How does Uno know I want to use A4 & A5 as SDA/SCL and not as analog inputs? Do I need to include the Wire library?

My chinese Uno has D16 & D17 labeled as SDA/SCL. I guess I'll toggle the various SCL pins to see what I have.

Thanks for your interest.

If you use Wire.begin() it knows you want to use sda & scl. If you use analogRead(A4) or analogRead(A5) it knows you want analog. Yes, you must include the Wire library to use sda/scl.

I never heard of an Uno with D16/17 pins. Uno clones normally have the same pins as a genuine Uno, otherwise they can't sell themselves as clones.

Paul

Tilemachos:
Can I use sda-scl pins for an lcd and pins 4 and 5 as buttons or sensors, in the same time?

Not directly. You can connect multiple chips/devices using I2C though. If one is an LCD and another is a port-expander, you can display your info and read buttons using the expander and just use 2 arduino-pins.
There are quite a lot of devices working with I2C by the way.

You can use digitalWrite(17,1) to write to A3... (not A5!)
It's:

A0: 14
A1: 15
A2: 16
A3: 17
A4: 18
A5: 19

DrAzzy:
You can use digitalWrite(17,1) to write to A3... (not A5!)
It's:

A0: 14
A1: 15
A2: 16
A3: 17
A4: 18
A5: 19

Oh, yes, i had forgotten. Thanks for the reminder, Doc. Why not A5? I knew A6 & A7 are analog only on Nano.

Hi,

The good news is... yes, of course, you can. The not-so-good news is... no, you can't just throw a switch with its resistor on A4-A5 if you intend to use I2C for something else.
This article: DIY I2C Devices With ATtiny85 | Hackaday explains how to make a slave I2C device with an ATTiny85, such as a joystick, buttons and so on.
Now, a LED screen is much more responsive on SPI and, IMHO, single buttons are a waste of analog pins.