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()
Steve Robillard
  • 34,988
  • 18
  • 106
  • 110
user3709398
  • 13
  • 1
  • 3

2 Answers2

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()
Wilf
  • 2,533
  • 3
  • 23
  • 39
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

MatsK
  • 2,882
  • 3
  • 17
  • 22