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?
-
Upvoting and choosing an answer is the way to show your appreciation on this site.Steve Robillard– Steve Robillard2016年03月25日 05:02:16 +00:00Commented Mar 25, 2016 at 5:02
-
I have the same question, but I am using the gpiozero module. But same problem/issue.RufusVS– RufusVS2018年12月04日 17:48:55 +00:00Commented Dec 4, 2018 at 17:48
3 Answers 3
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.
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.
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).