0

Yesterday I got my brand new RasPi 3 model B. The package included a full GPIO equipment. After few minutes I was ready to launch everything and it works wonderfully, except for one strange behaviour: I wanted to play around with GPIO, I set everything up (Hardware & Updates/Upgrades) and wrote a simple Python script:

#!/usr/bis/python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.Setup(17,GPIO.OUT)
GPIO.Setup(6,GPIO.OUT)
Print ("Test")
GPIO.Output(17,GPIO.HIGH)
GPIO.Output(6,GPIO.HIGH)
GPIO.cleanup()

When I run it I get following Error:

pi@Raspi2:~ $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
GPIO.Setup(17,GPIO.OUT)
AttributeError: 'module' object has no attribute 'Setup'

When I manually type it into python console, everything works fine. Can somebody explain why this happens?

1
  • 2
    Also note that your script should start with #!/usr/bin/python, bin not bis.
    – matsjoyce
    Commented Oct 28, 2016 at 10:32

3 Answers 3

3

I'm not a python user but a quick search around here implies this is a case sensitivity issue. I.e., you want:

GPIO.setup(17,GPIO.OUT)

I'd suggest also investing some time in starting with some basic python use tutorials (just click through the version 2 or 3 button there). I know pesky things like basic syntax can seem like they are too simple to have to bother learning first, but trying to learn them at the same time as you do something else (e.g., working with the GPIOs) can quickly and easily, as we see here, lead to confusion and frustration that is likely to grow more and more gnarled as you proceed.

2

The correct function to call is 'setup' not 'Setup'.

You can see some examples HERE

0
2

AttributeError is raised when the requested attribute of the object is not available which in most cases means it does not exist. Having it miss-spelled (considering Python's case sensitivity) is probably a common mistake for beginners. In the provided sample code the same issue applies to the output and print lines:

print ("Test")
GPIO.output(17,GPIO.HIGH)

Besides checking the documentation of the module, in this case RPi.GPIO, you can easily list the valid attributes for the module using dir(), e.g.:

dir(RPi.GPIO)

This returns a list of valid attributes. It will be directly output if issued at an interactive shell or can be printed when executing a script.

And some more resources to check:

While not directly related to the Pi they provide a good start. Going through all the material might take a few days but it will pay off in the long run.

1
  • Thank you, I will check out these resources for sure. Have a nice day
    – Lancakyr
    Commented Oct 28, 2016 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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