class ADC – Analog to Digital Conversion
Quick Usage Example
import machine
adc = machine.ADC() # create an ADC object
apin = adc.channel(pin='P16') # create an analog pin on P16
val = apin() # read an analog value
Constructors
Create an ADC object; associate a channel with a pin. For more info check the hardware section.
Methods
Enable the ADC block. This method is automatically called on object creation.
Bitscan take values between 9 and 12 and selects the number of bits of resolution of the ADC block.
Disable the ADC block.
Create an analog pin.
pinis a keyword-only string argument. Valid pins areP13toP20.attnis the attenuation level. The supported values are:ADC.ATTN_0DB ADC.ATTN_2_5DB ADC.ATTN_6DB ADC.ATTN_11DB
Returns an instance of ADCChannel. Example:
# enable an ADC channel on P16
apin = adc.channel(pin='P16')
Constants
ADC channel attenuation values
class ADCChannel
Read analog values from internal/external sources. ADC channels can be connected to internal points of the MCU or to GPIO pins. ADC channels are created using the ADC.channel method.
Methods
Fast method to read the channel value.
Read the channel value.
(Re)init and enable the ADC channel. This method is automatically called on object creation.
Disable the ADC channel.
ADC pin input range is 0-1.1V. This maximum value can be increased up to 3.3V using the highest attenuation of 11dB. Do not exceed the maximum of 3.3V, to avoid damaging the device.