Page 1 of 1

GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 24, 2013 8:25 am
by darthvazor

Code: Select all

#!/usr/bin/env python2.7
# script by Alex Eames http://RasPi.tv
# http://RasPi.tv/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)

# GPIO 23 & 17 set up as inputs, pulled up to avoid false detection.
# Both ports are wired to connect to GND on button press.
# So we'll be setting up falling edge detection for both
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# GPIO 24 set up as an input, pulled down, connected to 3V3 on button press
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
time_stamp = time.time()
time_stamp2 = time.time()

# now we'll define two threaded callback functions
# these will run in another thread when our events are detected
def my_callback():
    global time_stamp       # put in to debounce
    time_now = time.time()
    if (time_now - time_stamp) >= 0.3:
        print "falling edge detected on 17"
    time_stamp = time_now

def my_callback2():
    global time_stamp2       # put in to debounce - note we need a second time stamp
    time_now = time.time()
    if (time_now - time_stamp2) >= 0.3:
        print "falling edge detected on 23"
    time_stamp2 = time_now

print "Make sure you have a button connected so that when pressed"
print "it will connect GPIO port 23 (pin 16) to GND (pin 6)\n"
print "You will also need a second button connected so that when pressed"
print "it will connect GPIO port 24 (pin 18) to 3V3 (pin 1)\n"
print "You will also need a third button connected so that when pressed"
print "it will connect GPIO port 17 (pin 11) to GND (pin 14)"
raw_input("Press Enter when ready\n>")

# when a falling edge is detected on port 17, regardless of whatever 
# else is happening in the program, the function my_callback will be run
GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback)

# when a falling edge is detected on port 23, regardless of whatever 
# else is happening in the program, the function my_callback2 will be run
GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback2)

try:
    print "Waiting for rising edge on port 24"
    GPIO.wait_for_edge(24, GPIO.RISING)
    print "Rising edge detected on port 24. Here endeth the third lesson."

except KeyboardInterrupt:
    GPIO.cleanup()       # clean up GPIO on CTRL+C exit
GPIO.cleanup()           # clean up GPIO on normal exit
I tried this tutorial code and it didn't work. The error said:

Traceback (most recent call last):
File "test1.py", line 6, in <module>
GPIO.setmode(GPIO.BCM)
AttributeError: 'module' object has no attribute 'setmode'

I tried GPIO.BOARD too and it still not working. I already installed RPi.GPIO most current version 0.5.1a. Please help me, your help would be appreciated.

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 24, 2013 8:47 am
by malakai
What happens when you run this:

Code: Select all

sudo python
import RPi.GPIO as GPIO
GPIO.VERSION
I would imagine if it errors there is a problem with the RPi.GPIO do you have a file named RPi.GPIO in the same directory?

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 24, 2013 8:53 am
by alexeames
Sounds like you have an old version of RPi.GPIO. Setmode was introduced in August 2011. In "Pi speed" that's about 4 generations ago. :lol:

It shows you how to update on the same page you got the code from.

The interrupts were only released last week, you need the very latest RPi.GPIO 0.5.1a for this script to work. (And there will be an even newer version soon with PWM and debounce).

Is it possible your install went wrong? How did you do it?

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 24, 2013 9:32 am
by croston
Sounds like you have installed RPi.GPIO manually from source at some point. What is the result of:

Code: Select all

$ find /usr | grep -i gpio

Re: GPIO.setmode(GPIO.BCM) error

Posted: Mon Mar 25, 2013 7:09 pm
by darthvazor
@ Croston

Code: Select all

/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.1a.egg-info
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.1a.egg-info/top_level.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.1a.egg-info/SOURCES.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.1a.egg-info/dependency_links.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.1a.egg-info/PKG-INFO
/usr/lib/python2.6/dist-packages/RPi/GPIO.so
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.1a.egg-info
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.1a.egg-info/top_level.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.1a.egg-info/SOURCES.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.1a.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.1a.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/RPi/GPIO.so
/usr/lib/python3/dist-packages/RPi/GPIO.cpython-32mu.so
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/top_level.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/SOURCES.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/PKG-INFO
/usr/lib/pyshared/python2.6/RPi/GPIO.so
/usr/lib/pyshared/python2.7/RPi/GPIO.so
/usr/share/doc/python-rpi.gpio
/usr/share/doc/python-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python-rpi.gpio/copyright
/usr/share/doc/python-rpi.gpio/changelog.gz
/usr/share/doc/python3-rpi.gpio
/usr/share/doc/python3-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python3-rpi.gpio/copyright
/usr/share/doc/python3-rpi.gpio/changelog.gz
/usr/share/pyshared/RPi.GPIO-0.5.1a.egg-info
/usr/share/pyshared/RPi.GPIO-0.5.1a.egg-info/top_level.txt
/usr/share/pyshared/RPi.GPIO-0.5.1a.egg-info/dependency_links.txt
/usr/share/pyshared/RPi.GPIO-0.5.1a.egg-info/PKG-INFO
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.5.3-py2.7-linux-armv6l.egg/_web                                                         iopi/GPIO.py
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.5.3-py2.7-linux-armv6l.egg/_web                                                         iopi/GPIO.so
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.5.3-py2.7-linux-armv6l.egg/_web                                                         iopi/GPIO.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/__init__.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init_                                                         _.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init_                                                         _.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/__init__.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/zip-saf                                                         e
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/top_lev                                                         el.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/SOURCES                                                         .txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/depende                                                         ncy_links.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/PKG-INF                                                         O
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.5.3-py3.2-linux-armv6l.egg/_web                                                         iopi/GPIO.py
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.5.3-py3.2-linux-armv6l.egg/_web                                                         iopi/__pycache__/GPIO.cpython-32.pyc
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.5.3-py3.2-linux-armv6l.egg/_web                                                         iopi/GPIO.cpython-32mu.so
/usr/local/bin/gpio
/usr/local/share/man/man1/gpio.1
@Malakai

Code: Select all

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.VERSION
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VERSION'

Re: GPIO.setmode(GPIO.BCM) error

Posted: Mon Mar 25, 2013 7:36 pm
by croston
Spotted your problem. You have manually installed RPi.GPIO 0.1.0 at some point in the distant past and this one takes precidence over any copy installed using apt-get.

To remove it:

Code: Select all

$ sudo rm -rf /usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0*

Re: GPIO.setmode(GPIO.BCM) error

Posted: Mon Mar 25, 2013 7:48 pm
by darthvazor
It works! Thank you, Croston! :)

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 31, 2013 2:58 pm
by adelghouari
hi all; me too i have this problem; i"m going to preperd this my ferst exempal with my pi; but if i make sudo python

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 31, 2013 3:13 pm
by adelghouari
after these commands ligne

[email protected] ~ $ sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmod(GPIO.BCM)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setmod'
i"m not understand; but after reading your messages i make this

>>> GPIO.VERSION
'0.5.2a'
there is not others version of GPIO.

sorry; if i make >> GPIO.setmod(GPIO.BCM)

Code: Select all

@raspberrypi ~ $ find /usr | grep -i gpio
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/SOURCES.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/lib/python2.6/dist-packages/RPi/GPIO.so
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/SOURCES.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/RPi/GPIO.so
/usr/lib/python3/dist-packages/RPi/GPIO.cpython-32mu.so
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/top_level.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/SOURCES.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.4.1a.egg-info/PKG-INFO
/usr/lib/pyshared/python2.6/RPi/GPIO.so
/usr/lib/pyshared/python2.7/RPi/GPIO.so
/usr/share/doc/python-rpi.gpio
/usr/share/doc/python-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python-rpi.gpio/copyright
/usr/share/doc/python-rpi.gpio/changelog.gz
/usr/share/doc/python3-rpi.gpio
/usr/share/doc/python3-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python3-rpi.gpio/copyright
/usr/share/doc/python3-rpi.gpio/changelog.gz
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
please i need your help thank you

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 31, 2013 3:16 pm
by croston
Try using setmode with an 'e' on the the end, not setmod.

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Mar 31, 2013 3:24 pm
by adelghouari
croston thank you; i'm not good today
thank's

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sun Jun 09, 2013 2:11 pm
by alexszilagyi
Hi there,

I'm running in the same issue, can anyone help me to check my log:

Code: Select all

/usr/share/webiopi/htdocs/app/gpio-list
/usr/share/webiopi/htdocs/app/gpio-list/index.html
/usr/share/webiopi/htdocs/app/gpio-header
/usr/share/webiopi/htdocs/app/gpio-header/index.html
/usr/share/doc/python3-rpi.gpio
/usr/share/doc/python3-rpi.gpio/copyright
/usr/share/doc/python3-rpi.gpio/changelog.gz
/usr/share/doc/python3-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python-rpi.gpio
/usr/share/doc/python-rpi.gpio/copyright
/usr/share/doc/python-rpi.gpio/changelog.gz
/usr/share/doc/python-rpi.gpio/changelog.Debian.gz
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/share/pyshared/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/SOURCES.txt
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/RPi/GPIO.so
/usr/lib/pyshared/python2.7/RPi/GPIO.so
/usr/lib/pyshared/python2.6/RPi/GPIO.so
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.2a.egg-info
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.2a.egg-info/SOURCES.txt
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/RPi/GPIO.cpython-32mu.so
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/top_level.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/PKG-INFO
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/SOURCES.txt
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.2a.egg-info/dependency_links.txt
/usr/lib/python2.6/dist-packages/RPi/GPIO.so
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi/GPIO.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi/GPIO.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi/__init__.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi/__init__.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/RPi/GPIO.so
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/top_level.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/PKG-INFO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/SOURCES.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/dependency_links.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/native_libs.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.2a-py2.7-linux-armv6l.egg/EGG-INFO/zip-safe
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-armv6l.egg/webiopi/devices/digital/gpio.pyc
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-armv6l.egg/webiopi/devices/digital/gpio.py
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-armv6l.egg/_webiopi/GPIO.pyc
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-armv6l.egg/_webiopi/GPIO.py
/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-armv6l.egg/_webiopi/GPIO.so
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/devices/digital/__pycache__/gpio.cpython-32.pyc
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/devices/digital/gpio.py
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/_webiopi/__pycache__/GPIO.cpython-32.pyc
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/_webiopi/GPIO.py
/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/_webiopi/GPIO.cpython-32mu.so
While running this: https://dpaste.de/qWLad/ I get this: http://severo.ro/RaspberryPi/ModuleNotI ... rectly.png


I'd appreciate any help ;)

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Oct 18, 2013 9:27 am
by vijay_nav
i am facing the same error can any help me
this is my code

import RPi.GPIO as GPIO
GPIO.setmode(gpio.BCM)
GPIO.setup(7,GPIO.IN)
GPIO.setup(8,GPIO.OUT)
input_value=GPIO.input(7)
GPIO.output(8,True)
while executing the code i am getting the error as

Traceback (most recent call last):
File "vijay.py", line 2, in <module>
GPIO.setmode(gpio.BCM)
NameError: name 'gpio' is not defined
i have checked with my gpio package
usr/share/doc/python3-rpi.gpio
/usr/share/doc/python3-rpi.gpio/copyright
/usr/share/doc/python3-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python3-rpi.gpio/changelog.gz
/usr/share/doc/python-rpi.gpio
/usr/share/doc/python-rpi.gpio/copyright
/usr/share/doc/python-rpi.gpio/changelog.Debian.gz
/usr/share/doc/python-rpi.gpio/changelog.gz
/usr/share/pyshared/RPi.GPIO-0.5.3a.egg-info
/usr/lib/python2.7/dist-packages/RPi/GPIO.so
/usr/lib/python2.7/dist-packages/RPi.GPIO-0.5.3a.egg-info
/usr/lib/python3/dist-packages/RPi/GPIO.cpython-32mu.so
/usr/lib/python3/dist-packages/RPi.GPIO-0.5.3a.egg-info
/usr/lib/python2.6/dist-packages/RPi/GPIO.so
/usr/lib/python2.6/dist-packages/RPi.GPIO-0.5.3a.egg-info
/usr/lib/pyshared/python2.7/RPi/GPIO.so
/usr/lib/pyshared/python2.6/RPi/GPIO.so
please help me .....................................

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Oct 18, 2013 9:44 am
by vijay_nav
who get's error of Traceback (most recent call last):
File "vijay.py", line 2, in <module>
GPIO.setmode(gpio.BCM)
NameError: name 'gpio' is not defined
just try with this GPIO.setmode(GPIO.BOARD)
instead of GPIO.setmode(GPIO.BCM)

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Oct 18, 2013 10:04 am
by clive
Python is case sensitive : use 'GPIO' not 'gpio' in line 2

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Oct 18, 2013 10:07 am
by clive
vijay_nav wrote:who get's error of Traceback (most recent call last):
File "vijay.py", line 2, in <module>
GPIO.setmode(gpio.BCM)
NameError: name 'gpio' is not defined
just try with this GPIO.setmode(GPIO.BOARD)
instead of GPIO.setmode(GPIO.BCM)
just be aware that the pins will be referenced in numerical order in BOARD mode.

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Feb 08, 2019 9:48 pm
by TimDeWeasel
When i try to run example code from CanaKit's included star-up booklet Raspberry Pi for Dummies.

import RPi.GPIO
import time
LED_on = True
LED_off = False
GPIO.setmode (GPIO.BCM)
GPIO.setupmode (18, GPIO.OUT)
GPIO.output (18, LED_on)

When I try to run it I get the following:

Traceback (most recent call last):
File "/home/pi/one LED.py". line 5 in <module>
GPIO.setmode (GPIO.BCM)
NameError: name 'GPIO' is not defined


I am obviously new to Python and Linux and do not know enough to debug this problem.

Re: GPIO.setmode(GPIO.BCM) error

Posted: Fri Feb 08, 2019 11:15 pm
by B.Goode
Welcome to the Raspberry Pi forums.

TimDeWeasel wrote:
Fri Feb 08, 2019 9:48 pm
When i try to run example code from CanaKit's included star-up booklet Raspberry Pi for Dummies.

import RPi.GPIO
import time
LED_on = True
LED_off = False
GPIO.setmode (GPIO.BCM)
GPIO.setupmode (18, GPIO.OUT)
GPIO.output (18, LED_on)

When I try to run it I get the following:

Traceback (most recent call last):
File "/home/pi/one LED.py". line 5 in <module>
GPIO.setmode (GPIO.BCM)
NameError: name 'GPIO' is not defined


I am obviously new to Python and Linux and do not know enough to debug this problem.

If you have a problem with code or documentation supplied on a commercial basis by a third party perhaps you should seek advice from them.

The error message is quite succinct and accurate: nowhere in your script do you provide a definition of GPIO.

The usual way to make RPi.GPIO features available within your script is to use the following:

Code: Select all

import RPi.GPIO as GPIO


Edit: just to add - the documentation here http://www.canakit.com/Media/CanaKit-Ra ... de-3.2.pdf appears to show the first line of the sample scripts as I have indicated.

Re: GPIO.setmode(GPIO.BCM) error

Posted: Sat Feb 09, 2019 12:31 pm
by TimDeWeasel
;) That did it! thanks