mccoy
Posts: 15
Joined: Tue Mar 07, 2017 11:41 pm

GPIO LED not working

Thu Mar 09, 2017 9:08 pm

Hi, I'm trying to just get a LED to turn on but I'm having no luck.
I have the LED going into a ground and GPIO 18/number 12. Here is my code.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(10)
print "LED off"
GPIO.output(18,GPIO.LOW)
I've checked the GPIO pins with gpio readall. I can get it to switch from 0 to 1 no problem, switches to output no problem. I've plugged the LED into the 3.3V on the top and I get light. I'm using two 220 ohm resistors (didn't have a 330).
I've tried pins other than 18 but no luck. I downloaded pigpio, ran gpiotest and piscope and everything looks good.
What am I doing wrong?

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: GPIO LED not working

Thu Mar 09, 2017 9:49 pm

mccoy wrote:Hi, I'm trying to just get a LED to turn on but I'm having no luck.
I have the LED going into a ground and GPIO 18/number 12. Here is my code.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(10)
print "LED off"
GPIO.output(18,GPIO.LOW)
I've checked the GPIO pins with gpio readall. I can get it to switch from 0 to 1 no problem, switches to output no problem. I've plugged the LED into the 3.3V on the top and I get light. I'm using two 220 ohm resistors (didn't have a 330).
I've tried pins other than 18 but no luck. I downloaded pigpio, ran gpiotest and piscope and everything looks good.
What am I doing wrong?
You seem to be doing the right things. if gpio readall shows the pin state changing when your code runs, and the LED works from 3.3v, I suggest you triple check what pin you are connecting to. BCM pin 18 is physical pin 12, as you say. Re-check the polarity of the the LED. The pin that was on 3.3V when it worked going to the GPIO pin and the other pin to GND.

If you have volt meter check what voltage appears on the pin when you set it high and low.

The pin circuitry could be damaged. Try a different gpio number. Try connecting the LED from 3.3V to GPIO pin, taking care to connect the other end of the LED to the GPIO so the polarity is correct.

mccoy
Posts: 15
Joined: Tue Mar 07, 2017 11:41 pm

Re: GPIO LED not working

Fri Mar 10, 2017 4:25 pm

PiGraham wrote:
mccoy wrote:Hi, I'm trying to just get a LED to turn on but I'm having no luck.
I have the LED going into a ground and GPIO 18/number 12. Here is my code.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(10)
print "LED off"
GPIO.output(18,GPIO.LOW)
I've checked the GPIO pins with gpio readall. I can get it to switch from 0 to 1 no problem, switches to output no problem. I've plugged the LED into the 3.3V on the top and I get light. I'm using two 220 ohm resistors (didn't have a 330).
I've tried pins other than 18 but no luck. I downloaded pigpio, ran gpiotest and piscope and everything looks good.
What am I doing wrong?
You seem to be doing the right things. if gpio readall shows the pin state changing when your code runs, and the LED works from 3.3v, I suggest you triple check what pin you are connecting to. BCM pin 18 is physical pin 12, as you say. Re-check the polarity of the the LED. The pin that was on 3.3V when it worked going to the GPIO pin and the other pin to GND.

If you have volt meter check what voltage appears on the pin when you set it high and low.

The pin circuitry could be damaged. Try a different gpio number. Try connecting the LED from 3.3V to GPIO pin, taking care to connect the other end of the LED to the GPIO so the polarity is correct.
Thanks for your reply. I've checked with other pins but have the same trouble. I can get them to turn on but I can't get them to light the LED. Good idea on the voltmeter, I picked one up last night and will check it when I get to the lab today. I'll also run everything from scratch.

KMyers
Posts: 35
Joined: Fri Nov 09, 2012 9:46 pm

Re: GPIO LED not working

Fri Mar 10, 2017 6:21 pm

could be bad diode or possibly in backwards, I know I have put them in backwards several times!

Ken

Return to “Troubleshooting”