I have this code:

import RPi.GPIO as GPIO
import time

            GPIO.setup(3, GPIO.OUT)
            GPIO.setup(12, GPIO.OUT)
            GPIO.output(12, GPIO.HIGH)
            GPIO.output(3, GPIO.HIGH)
            GPIO.output(12, GPIO.LOW)
            GPIO.output(3, GPIO.LOW)

When the program exits, the LED connected to pin 3, (along with a 220 ohm resistor) stays on a little bit. Running gpio readall reveals that the pin has been set to IN. (Which is what I suspect is causing the issue; as running gpio export 2 out fixes the problem).

What am I doing wrong here?

  • A clear picture or diagram of your circuit could be useful... – Darth Vader Jun 1 '17 at 9:17
  • @DarthVader Sure! It's about as simple as possible. GPIO pin on the Pi > LED > 220ohm resistor > GND. – lightbord Jun 1 '17 at 12:26
  • GPIO.cleanup resets all pins to their default state (INPUT). If you don't call it, the pins will be left in whatever state you set them (but RPi.GPIO will whinge with a warning next time you run the script) – Dave Jones Jun 1 '17 at 15:47
  • @DaveJones then is it in this case acceptable to not call GPIO.cleanup? Or is there something I can do to my circuit to prevent the LED from glowing when the pin is put into input mode? Or another solution I'm not thinking of? – lightbord Jun 1 '17 at 15:54
  • Why don't you explicitly set the GPIO output pin driving the LED so it is off before you call the cleanup? – barny Jun 1 '17 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.