I have an LED connected to a GPIO pin and am using RPi.GPIO to control it. When setting up the GPIO pin, the LED blinks on ever so slightly when being initialized, which I don't want.

import RPi.GPIO as GPIO
GPIO.setup(22, GPIO.OUT)
GPIO.output(22, False)

setMode seems to briefly turn on the LED. Is there a way to prevent this? Is there a GPIO.setup(22, GPIO.OUT, default=False)?

  • What happens if you try to set the level before you make it an output? You could also examine the kernel source and see if there is a way to change the behavior. – Chris Stratton Nov 29 '12 at 21:49
  • if i do that it says I have to configure the pin before setting the level... – Scoop Nov 29 '12 at 23:34
  • That's usually not a requirement at the hardware level (though the rp gpios are somewhat atypical) so it might be worth looking through the driver source and seeing if you can change things. – Chris Stratton Nov 29 '12 at 23:37
  • Here is the exact error when I do thatL RPi.GPIO.WrongDirectionException: The GPIO channel has not been set up or is set up in the wrong direction – Scoop Nov 29 '12 at 23:43
  • 2
    Are you calling the GPIO.cleanup() method at the end of your program? Without it you might find you get odd results when the program is run multiple times as the GPIO will be left in the state it was when the program ended. – Martin O'Hanlon Dec 3 '12 at 15:37

This issue was resolved in the comments, as per this comment on the original post.

This is simply a place-holder post until the OP creates a self-answer.

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