1

I installed RPi.GPIO .5.1 and my uber basic led code says that the object has no attribute 'output'. I am hooking up the 12 pin to the Breadboard and I have ground hooked up too. Here is my python 2.7.7 code:

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(GPIO.OUT)
GPIO.output(12,GPIO.LOW)
GPIO.output(12,GPIO.HIGH)
time.sleep(3)
GPIO.cleanup()
1

What errors result when you run the script?

Here are a few potential errors I can see:

  • you could use from time import sleep instead of import time
  • you haven't put in the shebang line at the start of the script (#!/usr/bin/env python) - this tells what you are using to run it what it is.
  • You likely don't need GPIO.output(12,GPIO.LOW) as I would of thought that GPIO.output(12,GPIO.HIGH) would override it (you can also use GPIO.output(12, True)
  • With the GPIO.setup(GPIO.OUT) line, I think you need to specify the pin number - so it would be GPIO.setup(12, GPIO.OUT)

Another problem could be that you don't have it wired correctly - you can get help with pin numbers etc here. Try not get confused between the Board and BCM numbering

So something like this should work:

#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

GPIO.output(12, True))
print "On"
sleep(3)
print "Off"
GPIO.output(11, False)
GPIO.cleanup()
  • How did this solve your problem ? I have the same one and cannot figure out from where this comes from – ypicard Jul 8 at 12:57
  • @ypicard what error - "has no attribute 'output'." ? I guess it could the the extra ) in the code above otherwise... – Wilf Jul 10 at 17:41
0

This error 'module' object has no attribute 'output' means that the library which can access GPIO is not installed in it so, open your terminal

type: $ sudo apt-get install python-rpi.gpio python3-rpi.gpio

and then run your program if any warning occurs then add GPIO.setwarnings(False) to your code

  • 1
    the library which can access GPIO is not installed in it if that is the case then why does the script not crash at import or the calls to setmode and setup. Anyway, the previous answer was accepted as an answer so it apparently solved the problem. – Dirk Jan 9 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.