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)
joan
  • 71,852
  • 5
  • 76
  • 108
LilVinny
  • 450
  • 1
  • 4
  • 16

1 Answers1

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.

Shreyas Murali
  • 2,446
  • 1
  • 16
  • 23