I'm tinkering around with python and the raspberry pi's gpio pins. I wrote a simple program that prints the input of pin #7. When I connect the pin to the 3v3, there is a constant output of True. However, when I don't connect them there is no constant False output, but a random True/False output. This is probably not a software problem.

I am currently using a vnc client so I can't post any code (no copy and paste), but it's only an endless while loop that prints RPi.GPIO.input(7).

I have a B model from 2011.

有帮助吗?

解决方案

All you need is

GPIO.setup(7, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

from https://raspberrypi.stackexchange.com/questions/14680/raspberry-pi-gpio-input-pins-give-random-values

其他提示

Sounds like an electical issue. When you don't have anything connected the voltage on the pin "floats" as the ambient charge changes. Which can seem random.

To solve this ground the pin to 0.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top