User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

GPIO.cleanup() Question

Fri Aug 26, 2016 6:03 pm

Does GPIO.cleanup() reset all the pins to original state?

I see many Python scripts that exits with GPIO.cleanup(). But what if we do have Relays or Diodes connected to some of pins and we do not wish to reset those pins?

I found article that says:
RPi.GPIO provides a built-in function GPIO.cleanup() to clean up all the ports you’ve used. But be very clear what this does. It only affects any ports you have set in the current program. It resets any ports you have used in this program back to input mode.

But, how Raspberry GPIO knows that it can reset just pins in some Python script that we have used? Is this correct what I read about? Will My Relays and Diodes still having same state (on or off) untill some py script set GPIO.cleanup() because I have Button connected also and pin is set to INPUT?

Thanx,
Faramon

mattmiller
Posts: 2243
Joined: Thu Feb 05, 2015 11:25 pm

Re: GPIO.cleanup() Question

Fri Aug 26, 2016 6:23 pm

Best hing to do would be try it for yourself and see what happens

User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Re: GPIO.cleanup() Question

Fri Aug 26, 2016 7:08 pm

I try, all my others pins retain the state that they do have.

Faramon

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: GPIO.cleanup() Question

Fri Aug 26, 2016 11:37 pm

GPIO.cleanup() resets just the pins used by your python program that have changed state.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”