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,024
  • 5
  • 73
  • 106
LilVinny
  • 440
  • 1
  • 4
  • 16
  • 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 01: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 01: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 01: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 01:05
  • These are all the warnings I get. I don't see #4 in there anywhere. – LilVinny Sep 19 '16 at 01:06
  • @Sailormanenzo You should add additional information to your question (using the edit button). – joan Sep 19 '16 at 08:11

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,416
  • 1
  • 15
  • 22
  • 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 01:05
  • @Sailormanenzo try this GPIO.output([4, 7], GPIO.HIGH) – Shreyas Murali Sep 20 '16 at 01: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 01:16
  • Thanks but, the circuit im working on requires that if different values are inputed, different light turn on. – LilVinny Sep 20 '16 at 01:16
  • @Sailormanenzo try this `leds = [] # create a empty list if : 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 01:23
  • When I run the following, https://docs.google.com/document/d/1yhlOtEAcI4qCAzRam4hT5H3xgvQAonHG_k7QaJX2vVk/edit?usp=sharing I get: weather-test.py:8: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(channels, GPIO.OUT) Traceback (most recent call last): File "weather-test.py", line 12, in temperature = int(weather_com_result['current_conditions']['temperature']) KeyError: 'current_conditions' – LilVinny Sep 26 '16 at 00:40
  • I noticed couple of issues [1] the GPIO's seem to be in use (same as before) [2] the error is due to the weather data not containing the key (current_conditions). i have updated your script to include a print to see what exactly your are getting from the webapi – Shreyas Murali Sep 26 '16 at 01:04