import adc
The adc module exposes analog-to-digital reads for ESP32 pins. Use it when a MojoPython script needs sensor voltages, potentiometer positions, or other analog input values.
Quick example
import adc value = adc.read(34) millivolts = adc.read_mv(34) adc.config(34, 11, 12)
importadc
ADC native Berry module.
The adc module exposes analog-to-digital reads for ESP32 pins. Use it when a MojoPython script needs sensor voltages, potentiometer positions, or other analog input values.
API
3 available
adc.read(pin: int) -> int
adc.read(pin: int) -> intRead the raw ADC count from a pin.
Parameters
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pin |
int |
positional or keyword | Yes | ADC-capable GPIO pin or channel. |
Returns
int Integer raw ADC value reported by the native firmware.
adc.read_mv(pin: int) -> int
adc.read_mv(pin: int) -> intRead an ADC pin as millivolts.
Parameters
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pin |
int |
positional or keyword | Yes | ADC-capable GPIO pin or channel. |
Returns
int Integer millivolt reading after native calibration.
adc.config(pin: int, attenuation: int, width: int) -> any
adc.config(pin: int, attenuation: int, width: int) -> anyConfigure ADC attenuation and width for a pin.
Parameters
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pin |
int |
positional or keyword | Yes | ADC-capable GPIO pin or channel. |
attenuation |
int |
positional or keyword | Yes | Native attenuation value. |
width |
int |
positional or keyword | Yes | Native ADC width or resolution value. |
Returns
any Native success value, if the firmware returns one.