6

I intend to write a python script to change the status of GPIO pins. The code will receive arguments through sys.argv, change the state of some GPIO pins, and close afterward.

My question is: Do the state of GPIO pins (input/output) and their values (low/high) reset to the default state after the python script ends, or will their state persist until the next time the script runs and changes them again?

Jacobm001
11.9k7 gold badges48 silver badges58 bronze badges
asked Mar 24, 2016 at 15:33
2
  • Upvoting and choosing an answer is the way to show your appreciation on this site. Commented Mar 25, 2016 at 5:02
  • I have the same question, but I am using the gpiozero module. But same problem/issue. Commented Dec 4, 2018 at 17:48

3 Answers 3

13

If you're using RPi.GPIO and run .cleanup() at the end of your script, it will return the channel(s) back to inputs with no pull up/down. Otherwise, they will remain in the state you left them.

See https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/ for details.

Jacobm001
11.9k7 gold badges48 silver badges58 bronze badges
answered Mar 24, 2016 at 16:23
2
  • This is exactly what I was looking for. Thank you! Commented Mar 24, 2016 at 20:10
  • This may be the same issue with gpiozero, but it perhaps does the cleanup by default. Commented Dec 4, 2018 at 17:49
5

It depends on the module you are using and if you have changed the GPIO state using the module (rather than indirectly by calling a shell program to change the state).

My pigpio leaves the GPIO in the last set state.

I'm not sure about wiringPi (Python).

RPi.GPIO and RPIO.GPIO both have a cleanup function. If that is called then any GPIO you have changed with RPi or RPIO functions will be set as inputs with no (resistor) pulls.

answered Mar 24, 2016 at 18:24
0
2

Status (input/output direction and value) will stay as set until they are changed again - unless your script explicitly messes with them (the other answers got that covered).

answered Mar 24, 2016 at 16:04
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.