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
- 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)
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.