Page 1 of 1

Release (machine.)Pin resources?

Posted: Mon Aug 08, 2022 4:57 pm
by Jibun no kage
I happen to be working with a Pico image. Was looking for a way to release or clean up Pin allocation? For example in Pi OS, GPIO.cleanup(). But for (machine.)Pin, no method?

>>> from machine import Pin
>>> dir(Pin)
['__class__', '__name__', 'value', '__bases__', '__dict__', 'ALT', 'IN', 'IRQ_FALLING', 'IRQ_RISING', 'OPEN_DRAIN', 'OUT', 'PULL_DOWN', 'PULL_UP', 'high', 'init', 'irq', 'low', 'off', 'on', 'toggle']

Was expecting, maybe, 'deinit'?

Re: Release (machine.)Pin resources?

Posted: Mon Aug 08, 2022 5:17 pm
by scruss
With MicroPython, that's left up to you. Since pins aren't guaranteed to be initialized in a known state on powerup, it might be hard to know what state to leave them in.

Re: Release (machine.)Pin resources?

Posted: Mon Aug 08, 2022 11:10 pm
by Jibun no kage
Yeah, I guess a reasonable compromise is to always leave a given pin something consistent, maybe Pin.OUT, 0. But I was also thinking of releasing the resources of the actual Pin object, but that should or could be handled via object variable set to None, then call gc.collect(), right?

Re: Release (machine.)Pin resources?

Posted: Thu Aug 11, 2022 1:22 am
by jimmo
On most ports (including rp2) the pins are statically allocated in RAM and do not live in the heap, there's nothing to free. (See the table at the top of rp2/machine_pin.c)

Re: Release (machine.)Pin resources?

Posted: Thu Aug 11, 2022 1:24 am
by Jibun no kage
Ah, good to know, if a bit of bummer.