class ADC – analog to digital conversion¶
The ADC class wraps a single analog-to-digital converter
channel that samples a voltage on a pin (or one of the on-chip
analog channels) and returns its discretised value.
Example usage:
from machine import ADC, Pin
adc = ADC(Pin("P6")) # ADC channel on header pin P6 (PA5)
val = adc.read_u16() # raw reading scaled to 0..65535
Constructors¶
- class machine.ADC(id: int | str | Pin) ADC¶
Construct an
ADCobject for the analog source identified byid. The accepted forms are:Methods¶
Constants¶
The constants below are only available on the STM32 port; pass them as the
idargument to construct anADCthat reads one of the on-chip analog sensors. The result ofread_u16()is the channel’s raw 16-bit reading; for calibrated values use the helpers onpyb.ADCAll.