Closed
Description
When you use a Pin for ADC it can never be a gpio pin until a hard reset is done.
Example:
p = Pin(36, Pin.IN)
p() # Yields 1 since it is conncted to 3.3V via external pull-up
a = ADC(Pin(36))
a.read() # Yields 4095 on standard attenuation
del a
p = Pin(36, Pin.IN)
p() # Yields 0 but should be 1
Cause: When the pin is taken for the ADC the primary mux is set to connect to the RTC_ADC. Subsequent re-initialisation with Pin() or Pin.init does not switch the mux back. This normally works because after reboot, by default the primary mux connects to the GPIO mux.
As a solution we could reset the pin before selecting in machine_pin_obj_init_helper()
in machine_pin.c. This seems to work well:
// configure the pin for gpio
gpio_reset_pin(self->id); # restores defaults, similar to reboot
gpio_pad_select_gpio(self->id);