Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
Upvoting and choosing an answer is the way to show your appreciation on this site. – Steve Robillard Mar 25 at 5:02
up vote 12 down vote accepted

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.

share|improve this answer
    
This is exactly what I was looking for. Thank you! – Ali Fatolahzadeh Mar 24 at 20:10

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.