2

Except for the 5V, 3.3V and ground pins on the Raspberry PI, can I use any other pin as input on the Pi?

I've connected it to the I2C pins, but it doesn't want to read the input.

I used GPIO.setup command to set it as an input. Other inputs on for instance GPIO 4 works fine.

  • Try setting up the (digital GPIO) pin as an OUTPUT, but then read it as if it were an INPUT pin. This will return the state of the pin even though it in OUTPUT mode. I know for sure that this trick works for Arduino or RPi, but I'm pretty sure it works both. – user39664 Jul 18 '16 at 14:36
4

Technically the 5V, 3V3 and GND are not GPIO pins - as it reads General Purpose Input Output pins.

With respect to the I2C pins it is noteworthy that they indeed behave differently both on the hardware and software side. They include a hard-wired pull-up resistor (1K8) and the kernel includes a generic driver i2c_dev that claims those pins (and might be loaded on start-up).

See also elinux.org.

  • Does that mean I can't use them as inputs? I'm using the first circuit here: elinux.org/RPi_GPIO_Interface_Circuits , except I added 1k resistor between the pin and the switch. – Johan Nov 6 '15 at 22:07
  • @Johan that would work if you remove the resistor. With the resistor the pin won't be pulled low enough. (And obviously you don't need another pullup.) – Milliways Nov 6 '15 at 22:09
  • @Milliways so should I remove both resistors then effectively the switch is just connected directly between the I2C pin and ground? Shouldn't I have a resistor in place if I accidentally press the switch while it is an output, otherwise it is a short between 3.3V and ground? – Johan Nov 6 '15 at 22:18
  • The risk of shorting to ground is greatly exaggerated. The chip has inbuilt current limiters which will prevent more than 8mA being drawn and is well protected. If it really worries you use a smaller series resistor. In conjunction with the 1.8kΩ pullup the series resistor must be smaller than 330Ω to reliably pull the pin low. – Milliways Nov 6 '15 at 23:37
3

All Pi GPIOs may be used as inputs or outputs.

Without seeing your circuit and software it is not possible to know what is being done incorrectly.

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.