Reputation: 41
I am testing my pi for the first time and i cant able to run the first program to light the led.
below is my code id from raspberry cookbook
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCD)
GPIO.setup(18,GPIO.OUT)
while(True):
GPIO.output(18, True)
time.sleep(1)
GPIO.output(18,False)
time.sleep(1)
when i run the script sudo python led.py it shows no error but the led has no output. I tried connecting a 360ohms between pin 18 and led. also tried connecting 540Ohms between pin 18 and led but no result.
Can anyone suggest how to debug the problem
Upvotes: 1
Views: 2507
Reputation: 41
Thanks all for the comments and suggestion, when I added the GPIO.clearup() and restarted the system it starts blinking....
below is the comeple code i used...
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCD)
GPIO.setup(18,GPIO.OUT)
while(True):
GPIO.output(18, GPIO.HIGH)
time.sleep(1)
GPIO.output(18,False)
time.sleep(1)
GPIO.CLEARUP()
THANKS EVERYONE FOR THE HELP....
Upvotes: 1
Reputation: 1367
This should blink the light on and off and worked for me
from time import sleep
import RPi.GPIO as gpio
gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)
gpio.output(18, True)
sleep(5)
gpio.output(18, False)
Upvotes: 1
Reputation: 6458
You should probably (and I don't know if either main stack or the EE-centric or the RPi spinoffs has a good way to do this inline) include some sort of diagram showing which pins you're connecting. At a minimum, you need to do GPIO 18 to LED to GND, and as LED is Light Emitting Diode or something to that effect, you need to make sure your LED is pointing in the correct direction. I'd suggest as a way to debug this partially, take python out of the loop and just configure the LED to be always on by writing a 1 to the appropiate /sys/blah/path. Also, http://elinux.org/RPi_Low-level_peripherals#sysfs (which has the path you need) points out... GPIO 24 is wired to P1_18 so you might want to double check that the pin you think is 18 is called 18 on both sides of the system.
Upvotes: 1