poing
Posts: 1132
Joined: Thu Mar 08, 2012 3:32 pm

GPIO strange behaviour

Wed Jan 02, 2013 3:18 pm

I'm trying to do one of the MagPi articles using an GPIO input. I don't get it, when I execute the following code:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)

while True:
	myval=GPIO.input(11)
	print myval
	time.sleep(0.2)
The output is:

Code: Select all

False
False
False
False
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
False
False
False
False
False
False
False
False
False
False
False
False
False
False
False
False
False
True
True
True
True
True
Basically 17 times "True" followed by 17 times "False" and so on. Why does this happen?

User avatar
croston
Posts: 708
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO strange behaviour

Wed Jan 02, 2013 3:23 pm

Have you got anything connected to that channel? If not, your input channel is 'floating'. This means that the input value is undefined electronically and therefore picks up electrical noise instead.

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO strange behaviour

Wed Jan 02, 2013 3:34 pm


Return to “Troubleshooting”