jeffocks
Posts: 3
Joined: Thu Feb 13, 2020 11:32 am

Beginner question SDA pin

Thu Feb 13, 2020 11:45 am

Hello, this is my first post. I'm following a project in a book and mostly it explains everything. But in a push button circuit it doesn't say what the link to the SDA GPIO pin (physical pin 3) actually does. The book talks about what switches do, but the way it is wired doesn't look to me that the button is doing what switches normally do - I'm sure it is but I can't see it! I've googled the SDA pin and searched the forums but can't work out exactly what is going on. I assume info is being fed to the PI that the button is depressed or not - but how does that complete or break a circuit?
Thanks!

User avatar
joan
Posts: 14755
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Beginner question SDA pin

Thu Feb 13, 2020 12:50 pm

Pins 3 and 5 of the Pi have hard-wired pull-ups to 3V3 fitted. Pin 3 is GPIO 2 (SDA). Pin 5 is GPIO 3 (SCL). The pull-ups are required for SDA/SCL to act as part of the I2C bus.

Because of the pull-ups those pins/GPIO will normally read high when used as inputs, unless an external switch connects them to ground (in which case they will read low).

jeffocks
Posts: 3
Joined: Thu Feb 13, 2020 11:32 am

Re: Beginner question SDA pin

Sat Feb 15, 2020 1:00 am

:shock: thanks very much for the reply, most appreciated...I think it will be a while though before I understand it! I need to stretch my vocabulary of pullups to more than what I might do in a car or gym!

User avatar
rpdom
Posts: 16332
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Beginner question SDA pin

Sat Feb 15, 2020 6:43 am

A pull-up (in this context) is a resistor between the GPIO pin and the +3.3V supply. It means that if nothing is actively connecting the pin to 0V, it will show as a 1 (high) value when used as an input.

If no "pull" value was used and nothing was feeding the pin a high (1) or low (0) value it would pick up random background interference and keep flipping between 1 and 0.

This only applies to pins used in an input mode. The i2c pins can be inputs or outputs, depending on what they need to be doing at the time.

Incidentally "SDA" is just one of the functions that pin can be assigned to do. Every pin has up to eight different modes of operation, it's just that pin 3 and 5 (GPIO 2 and 3) are frequently used with their i2c function, so are usually referred to as SCL and SDA. For example, pin 3 (GPIO 2 or SDA) can be set as: Input, Output, SDA1, DPI VSync (used as part of a video output), and there are four other modes, depending on which Pi you have. On the Pi 4b they can be CTS2, SDA3, SA3 and SPI3_MOSI. Those functions don't exist on earlier Pis.

jeffocks
Posts: 3
Joined: Thu Feb 13, 2020 11:32 am

Re: Beginner question SDA pin

Sat Feb 15, 2020 12:22 pm

Aha! rpdom nice one thank you - between the 2 replies I've had I'm getting it...I think! I'm using a Pi 3b+ so don't have to think about all those very interesting Pi4 functions just yet! But hope to get there too.

So, when the SDA assigned pin is high in my circuit my led is off - the switch effectively (when on) takes it to low when pressed. Interesting.

Thanks again

Return to “Beginners”