Among all the 40 GPIO pins, how many of them are available to connect a switch for on-off information?

I counted more than 24 GPIO_* connections here, but are they all available via Python?

import RPi.GPIO as GPIO
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
if GPIO.input(17):

enter image description here


The 40 pin expansion header connects to 28 GPIO. They are Broadcom GPIO 0 through 27.

You are recommended not to use GPIO 0/1 as they are intended to be used by HATs.

Any recent GPIO library will give access to all the GPIO connected to the expansion header.

  • Thanks. Can GPIO 2/3 be used for an open/closed switch? it seems that no, because of the pull-up resistor (?). Is there a way to use these 2 GPIO anyway?
    – Basj
    Mar 2 '17 at 23:23
  • 1
    You can use 2 and 3 for a button switch. You could connect the other end to ground when closed. The downside is just the waste of 3V3 through 1k8, or 2mA when the switch is operated.
    – joan
    Mar 2 '17 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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