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.

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() 
, here when try , run it.
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 $
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)

appreciated.

thanks,

the cleanup call should not in while loop.


raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support