kamhagh
Posts: 104
Joined: Sun Feb 09, 2014 3:30 pm

LED doens't blink :(

Tue Sep 02, 2014 2:12 pm

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?!!!

User avatar
DougieLawson
Posts: 36330
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: LED doens't blink :(

Tue Sep 02, 2014 2:20 pm

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)
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: LED doens't blink :(

Tue Sep 02, 2014 2:26 pm

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.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

kamhagh
Posts: 104
Joined: Sun Feb 09, 2014 3:30 pm

Re: LED doens't blink :(

Tue Sep 02, 2014 2:31 pm

so, i shoudl jsut connect it to 26 :O?

kamhagh
Posts: 104
Joined: Sun Feb 09, 2014 3:30 pm

Re: LED doens't blink :(

Tue Sep 02, 2014 2:36 pm

oh i got it now, thanks a lot :D this is the ebst forum ever :P

kamhagh
Posts: 104
Joined: Sun Feb 09, 2014 3:30 pm

Re: LED doens't blink :(

Tue Sep 02, 2014 2:45 pm

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

User avatar
joan
Posts: 14378
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: LED doens't blink :(

Tue Sep 02, 2014 2:51 pm

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.

Return to “Beginners”