Reading a GPIO Pin from Python 3 - Raspberry Pi Forums
hi,
had raspberry pi 2 day, fun.
have been able figure out number of things on own without trouble, until now.
i'm working book come raspberry pi, "vilors raspberry pi user's guide".
got page 167, "reading gpio pin python 3" without trouble.
reason i'm having trouble with, "reading gpio pin python 3".
believe basic circuit book told me build (just resistor , switch) working correctly because it's same circuit used for, "reading gpio pin terminal window" , works fine example, pages earlier in book.
believe it's .py file, life of me can't seem find solution.
here copy , past of code.
, here when try , run it.
appreciated.
thanks,
had raspberry pi 2 day, fun.
have been able figure out number of things on own without trouble, until now.
i'm working book come raspberry pi, "vilors raspberry pi user's guide".
got page 167, "reading gpio pin python 3" without trouble.
reason i'm having trouble with, "reading gpio pin python 3".
believe basic circuit book told me build (just resistor , switch) working correctly because it's same circuit used for, "reading gpio pin terminal window" , works fine example, pages earlier in book.
believe it's .py file, life of me can't seem find solution.
here copy , past of code.
code: select all
import rpi.gpio rpi.gpio.setmode (rpi.gpio.bcm) rpi.gpio.setup(2, rpi.gpio.in, pull_up_down=rpi.gpio.pud_up) while true: if rpi.gpio.input(2) == rpi.gpio.low: print ("switch pressed.") break rpi.gpio.cleanup()
don't understand why it's telling me set pin numbering mode when seem have in second line of code, rpi.gpio.setmode (rpi.gpio.bcm)pi@raspberrypi ~/desktop $ sudo python3 test.py
test.py:5: runtimewarning: physical pull resistor fitted on
channel!
rpi.gpio.setup(2, rpi.gpio.in, pull_up_down=rpi.gpio.pud_up)
traceback (most recent call last):
file "test.py", line 8, in <module>
if rpi.gpio.input(2) == rpi.gpio.low:
runtimeerror: please set pin numbering mode using
gpio.setmode(gpio.board) or gpio.setmode(gpio.bcm)
pi@raspberrypi ~/desktop $
appreciated.
thanks,
the cleanup call should not in while loop.
raspberrypi
Comments
Post a Comment