Page 1 of 1

LED doens't blink :(

Posted: Tue Sep 02, 2014 2:12 pm
by kamhagh
hi, i just recived my cute little pi! after lots of trouble trying to fix the dead micro sd card adapter i finally managed to install raspian on it :P

i tought its time for the real thing and wrote this code for python:

Code: Select all

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)
        return

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

for i in range(0,3):
        blink(11)
GPIO.cleanup()
the leds doesn't blink, its connected to pin 23, means GPIO 11 on my B+!

i also tried the GPIO 10 it didn't work either :( i tried directly connecting it to the first pin (3.3v+) and it turned on ! :( why isn't it blinking?!!!

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:20 pm
by DougieLawson
The pins can have up to four names.

RPi.GPIO defaults to BCM numbering, you've switched that to BOARD numbers just to help with confusing yourself.
Image

If you have the SPI driver loaded you can't use BCM pin # 11 (SPI SCLK pin) start with pin 4 (aka 7)

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:26 pm
by MattHawkinsUK
If you want to use physical pin numbers you use :

Code: Select all

GPIO.setmode(GPIO.BOARD)
If you want to use GPIO numbers you use :

Code: Select all

GPIO.setmode(GPIO.BCM)
Your code is using physical board pin 11 (GPIO17) but you've connected your LED to Pin 23 (GPIO11).

Connect your LED to Pin 11 and it should work.

Here is my Model B+ GPIO Reference Diagram.

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:31 pm
by kamhagh
so, i shoudl jsut connect it to 26 :O?

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:36 pm
by kamhagh
oh i got it now, thanks a lot :D this is the ebst forum ever :P

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:45 pm
by kamhagh
this is my new code:

Code: Select all

import RPi.GPIO as GPIO
import time
# blinking function
def blink(pin):
        GPIO.output(pin,GPIO.HIGH)
        time.sleep(1)
        GPIO.output(pin,GPIO.LOW)
        time.sleep(1)
        return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BCM)
# set up GPIO output channel
GPIO.setup(11, GPIO.OUT)
# blink GPIO17 50 times
for i in range(0,3):
        blink(11)
GPIO.cleanup()
it still doesn't work:(

edit: woops the led was broklen !!! sorry :) its blinking :P

Re: LED doens't blink :(

Posted: Tue Sep 02, 2014 2:51 pm
by joan
Broadcom gpio 11 is on pin 23. The B+ has more pins then the B so make sure you have the right pin, it is not next to the last pin.

Another common mistake is plugging in cobblers and ribbon cables back to front.

I have now seen your edit and know it's fixed.