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,904
  • 7
  • 47
  • 58
Ali F
  • 73
  • 1
  • 6

3 Answers3

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,904
  • 7
  • 47
  • 58
thephez
  • 310
  • 1
  • 8
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.

joan
  • 71,852
  • 5
  • 76
  • 108
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).

Ghanima
  • 15,958
  • 17
  • 65
  • 125