1

This is the code I used to test the LEDS on the GPIO. Every single LED worked, but the last LED, 4, wouldnt turn on. I have checked the wiring, The LED works, I even made sure the indents were in place.

import RPi.GPIO as GPIO

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)

GPIO.setup(25, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(8, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(14, GPIO.OUT)
GPIO.setup(9, GPIO.OUT)
GPIO.setup(10, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(4, GPIO.OUT)

GPIO.output(4, 1)
  • please fix the source formatting. python is very picky about the indentation also try enabling the warnings. there might be some useful messages that could help identify the problem – Shreyas Murali Sep 18 '16 at 22:51
  • gpio:7: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(25, GPIO.OUT) gpio:8: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(7, GPIO.OUT) gpio:9: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(8, GPIO.OUT) – LilVinny Sep 19 '16 at 1:04
  • gpio:10: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(24, GPIO.OUT) gpio:11: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(23, GPIO.OUT) gpio:12: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(18, GPIO.OUT) – LilVinny Sep 19 '16 at 1:04
  • gpio:13: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(15, GPIO.OUT) gpio:14: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(14, GPIO.OUT) gpio:15: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(9, GPIO.OUT) – LilVinny Sep 19 '16 at 1:05
  • gpio:16: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(10, GPIO.OUT) gpio:17: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(22, GPIO.OUT) gpio:18: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(17, GPIO.OUT) – LilVinny Sep 19 '16 at 1:05
1

Hardware check

  • make sure you have connected the led to right pin (many have been confused with the BCM mode vs Board mode of naming the pins) Below you can see BCM mode GPIO4 is actually Board mode pin 7

Pinout

  • make sure you didn't reverse bias the LED the final circuit
  • if you have a driver circuit check the driving transistor type pnp/npn and adjust the o/p (GPIO.HIGH or GPIO.LOW) accordingly
  • try using the swapping the LEDs from pin 4 on another port pin - should help determine if the led is defective or the problem is with the circuit/software

Software check

You can simplify/modify the above code like so

import RPi.GPIO as GPIO

channels = [4, 7, 8, 9, 10, 14, 15, 17, 18, 22, 23, 24, 25]

GPIO.setwarnings(True)
GPIO.cleanup(channels)
GPIO.setmode(GPIO.BCM) 
GPIO.setup(channels, GPIO.OUT)
GPIO.output(4, GPIO.HIGH)
  • add the GPIO.cleanup and use GPIO.HIGH as per the example here
  • try running as super user (like sudo python .\led.py)

  • share the circuit diagram

HTH

After looking further into the warning i am suspecting one or more pins are being used in their alternate functions mode

GPIO4  - none
GPIO7  - spi 0 chip en 1
GPIO8  - spi 0 chip en 0
GPIO9  - spi 0 miso
GPIO10 - spi 0 mosi
GPIO14 - uart 0 tx
GPIO15 - uart 0 rx
GPIO17 - none
GPIO18 - pcm clock
GPIO22 - none
GPIO23 - none
GPIO24 - none
GPIO25 - none

Assuming you dont have any other applications that use the SPI interface or the PCM clock, I think the pins GPIO14(usart tx) and GPIO15(usart rx) causing the warnings. Can you try the instructions here and disable the serial console and check if you still get warnings. If it does, it could collaterally fix your GPIO behavior too.

Just noticed you are missing GPIO.cleanup() which is required for clean exit.

  • GPIO4 Works now. However, there is a slight problem. When I try and light up two leds at the same time, only 1 turns on at a time. For example: GPIO.output(4, GPIO.HIGH) then GPIO.output(7, GPIO.HIGH) First #4 turns on then off, and right after that #7 turns on. – LilVinny Sep 20 '16 at 1:05
  • @Sailormanenzo try this GPIO.output([4, 7], GPIO.HIGH) – Shreyas Murali Sep 20 '16 at 1:14
  • @Sailormanenzo, if an answer worked for you, it would nice to accept it by clicking the tick mark near it. – Shreyas Murali Sep 20 '16 at 1:16
  • Thanks but, the circuit im working on requires that if different values are inputed, different light turn on. – LilVinny Sep 20 '16 at 1:16
  • @Sailormanenzo try this leds = [] # create a empty list if <condition1>: leds.append(<pin#>) # more conditions, add to the list as necessary and finally GPIO.output(leds, GPIO.HIGH) Also you might want to read up a bit of python if your are not already familiar – Shreyas Murali Sep 20 '16 at 1:23

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.