class ADC – analog to digital conversion: read analog values on a pin


import pyb

adc = pyb.ADC(pin)              # create an analog object on one of the 4 ADC channels
val =                # read an analog value
adc.deinit()                    # disable the adc channel
adc.init()                      # enable the adc channel


class pyb.ADC(pin)

Create an ADC object associated with the given pin. This allows you to then read analog values on that pin. For more info check the pinout and alternate functions table.


ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it can withstand). When GP2, GP3, GP4 or GP5 are remapped to the ADC block, 1.8 V is the maximum. If these pins are used in digital mode, then the maximum allowed input is 3.6V.


Read the value on the analog pin and return it. The returned value will be between 0 and 4095.


Enable the ADC channel.


Disable the ADC channel.