문제

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