2

I have a simple input setup via GPIO, on a headless PI (no video cables attached) The input it attached to a simple button. If I create a while loop and print out the status of the input, it goes back and forth between true and false when it should be false. If I press the button, it will read true correctly, but if I release the button, it will go back and forth between true and false (several times a second it seems)

If I touch the composite video output jack, it will just read false as it should. Anyone seen this?

3

f you program a pin as an input, and don't connect it, it's reasonable that you get a mix of high and low. This is because an input pin is somewhat like an open circuit - a little tiny capacitor, actually - and when connected to an open wire, it will just float up and down according to whatever RF field the wire is receiving. You could add a pullup resistor to avoid this - even a weak one like 100k-470k would prevent this.

Some of the rPi pins have pullups on the circuit board (GPIO0 and GPIO1, since they can be used as I2C that requires pullups).

You can use a pullup resistor to +3.3v, and then connect your button to ground, or use a pull-down resistor to ground, and connect the button to +3.3v. The first choice gives a 'backwards' result (switch ON=0) but it's more common for a number of reasons (one reason: it's better to have ground wired through a switch than to have the power wired through it).

  • 1
    The Pi has internal pull-up / pull-down 'resistors' on every GPIO line. These are software controlled == see here makezine.com/projects/… – Piman Feb 14 '15 at 9:34

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.