I am having a problem with a (apparently) very commonly used script for relay automation.
The script is as follows:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# init list with pin numbers
pinList = [2, 3, 4, 17, 27, 22, 10, 9]
# loop through pins and set mode and state to 'low'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# time to sleep between operations in the main loop
SleepTimeL = 2
# main loop
try:
GPIO.output(2, GPIO.LOW)
print "ONE"
time.sleep(SleepTimeL);
GPIO.output(3, GPIO.LOW)
print "TWO"
time.sleep(SleepTimeL);
GPIO.output(4, GPIO.LOW)
print "THREE"
time.sleep(SleepTimeL);
GPIO.output(17, GPIO.LOW)
print "FOUR"
time.sleep(SleepTimeL);
GPIO.output(27, GPIO.LOW)
print "FIVE"
time.sleep(SleepTimeL);
GPIO.output(22, GPIO.LOW)
print "SIX"
time.sleep(SleepTimeL);
GPIO.output(10, GPIO.LOW)
print "SEVEN"
time.sleep(SleepTimeL);
GPIO.output(9, GPIO.LOW)
print "EIGHT"
time.sleep(SleepTimeL);
GPIO.cleanup()
print "Good bye!"
# End program cleanly with keyboard
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
I have the latest Wheezy image as well as Phyton (2.6, 2.7 & 3, GPIO-0.5.2a & 0.5.5) .. When I use
./test.sh
(my script is named "test")
I get:
Traceback (most recent call last):
File "./test.sh", line 5, in <module>
GPIO.setmode(GPIO.BCM)
AttributeError: 'module' object has no attribute 'setmode'
So then I use:
bash -x text.sh
and get
+ import RPi.GPIO as GPIO
test.sh: line 2: import: command not found
+ import time
test.sh: line 3: import: command not found
+import time
test.sh: line 5: syntax error near unexpected token 'GPIO.BCM'
test.sh: line 5: 'GPIO.setmode(GPIO.BCM)
I have also tried
GPIO.setmode(BCM)
with the same results.
Any suggestions would be immensely appreciated. I am a complete n00b with the pi and this has been driving me nuts for....days.