0

I hope someone can help with this, i've looked at similar Q&A's but haven't found an answer that solves the basic question.

Right, trying to give all the info...

I'm using a first generation B+ board, recently updated using sudo apt dist-upgrade and trying to simply get a LED to light when a button is pressed and not before. Python 3 and Thonny.

import RPi.GPIO as GPIO
import time
GPIO.setmode (GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18,GPIO.HIGH)
time.sleep(5)
Print ("Done")
GPIO.cleanup()

The issue is that the LED lights on GPIO.setup line, not the GPIO.output high line where I would expect it to be. I went back to basics and tried just code for the LED as above with the same result.

Any help greatly appreciated.

3

When you set a GPIO to be an output it will be set to the last level it was set to while it was last an output. In your case it was last set high so it is set high when set as an output.

You need to explicitly set the GPIO low if you want it to be low.

| improve this answer | |

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.