Page 1 of 1

Python will not control an LED

Posted: Thu Jan 05, 2017 3:38 am
by Inexperienced
So, since I already have some experience with Python, I wanted to start programming stuff using Python instead of the Raspberry Pi terminal window thingy. I used this code (found on the Sunfounder website under 'Lesson 1: Blinking LED)

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
LedPin = 11 # pin11
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led
def loop():
while True:
print '...led on'
GPIO.output(LedPin, GPIO.LOW) # led on
time.sleep(0.5)
print 'led off...'
GPIO.output(LedPin, GPIO.HIGH) # led off
time.sleep(0.5)
def destroy():
GPIO.output(LedPin, GPIO.HIGH) # led off
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()

and it returned:
ValueError: The channel sent is invalid on a Raspberry Pi

Is there any way I can fix this and use Python to control devices on a breadboard? Or do I have to use the RPi terminal?