3

So I got an RPi and a canakit, I'm trying to follow a guide to get a simple program to make the LED blink. I have very little experience with RPis so it's probably a very simple error, but I can't figure out why it won't work. When I run the program I get a runtime error. I will post pictures of my wiring as well as the code. Thanks!

Wiring: http://i.imgur.com/RYv8lcW.jpg

Code:

import RPi.GPIO as GPIO
import time
#blink function
def blink(pin):
    GPIO.output(pin, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(pin, GPIO.LOW)
    time.sleep(1)
    return
#Use raspberry pi board numbers
GPIO.setmode(GPIO.BOARD)
#GPIO output channel
GPIO.setup(pin, GPIO.OUT)

for i in range(0,50):
    blink(11)
GPIO.cleanup()
  • Once you have reached a small amount of reputation (10, I believe) you can also include images as well (by using the picture icon in the top-bar of the edit frame) - as you have not quite got that I have done that for you. – SlySven Dec 27 '15 at 22:32
  • GPIO.setup(pin, GPIO.OUT) <- pin is not defined here. – user253751 Dec 28 '15 at 0:46
5

In your script, you have:

GPIO.setup(7, GPIO.OUT)

and then you call blink(11), which will lead to calling:

GPIO.output(11, GPIO.HIGH)

That is, the pin numbers don't match. You want to change both to 7 or both to 11.

import RPi.GPIO as GPIO
import time

def blink(pin):
    GPIO.output(pin, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(pin, GPIO.LOW)
    time.sleep(1)

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

pin = 7
blink(pin)
  • Lol wow, I figured it was something simple, but not that obvious. Thanks a bunch! – kalenpw Dec 27 '15 at 17:55

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.