mrfloppy88
Posts: 1
Joined: Mon Mar 31, 2014 12:52 pm

gpio.cleanup()

Mon Mar 31, 2014 1:17 pm

i need a GPIO pin to be HIGH after my script finishes...
at the moment GPIO.cleanup() turns it into INPUT, and this is no good for me...

can i setup the one pin and make it high after gpio.cleanup() has done its thing?
or can i prevent gpio.cleanup() to cleanup all pins, and just leave one active (i will set warnings off if this is the case)

thanks
Mrfloppy88

User avatar
croston
Posts: 708
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: gpio.cleanup()

Mon Mar 31, 2014 3:08 pm

I will be changing GPIO.cleanup() in the next release to be able specify certain pins to clean up. So in your case, you would need to do something like:

Code: Select all

# set up a list of the channels your program has used
channels_used = [2,4,6,7,8,9]

# clean up everything except channel 6
channels_used.remove(6)   # remove channel 6 from the list
for channel in channels_used:
    GPIO.cleanup(channel)
The code fix is this one:
http://sourceforge.net/p/raspberry-gpio ... ickets/52/

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: gpio.cleanup()

Tue Apr 01, 2014 6:49 pm

Ben, can you set it up so that it gives people a rather terse/rude/abusive message if they use

GPIO.cleanup()

before they've set up or used any ports? It seems very common indeed that people put it at the top of scripts thinking it gives them a fresh start.
Alex Eames RasPi.TV, RasP.iO

Return to “Python”