Chapter 2. API Reference
Vout = Dout * Vmax / Dmax (1)
where:
Vout Digital output result, standing for the voltage.
Dout ADC raw digital reading result.
Vmax Maximum measurable input analog voltage, see ADC Attenuation.
Dmax Maximum of the output ADC raw digital reading result, which is 8191 under Single Read mode, 4095
under Continuous Read mode.
For boards with eFuse ADC calibration bits, esp_adc_cal_raw_to_voltage() can be used to get the cal-
ibrated conversion results. These results stand for the actual voltage (in mV). No need to transform these data via
the formula (1). If ADC calibration APIs are used on boards without eFuse ADC calibration bits, warnings will be
generated. See ADC Calibration.
ADC Limitations
Note:
• Since the ADC2 module is also used by the Wi-Fi, reading operation of adc2_get_raw() may fail be-
tween esp_wifi_start() and esp_wifi_stop(). Use the return code to see whether the reading is
successful.
Driver Usage
Both of the ADC units support single read mode, which is suitable for low-frequency sampling operations.
Note: ADC readings from a pin not connected to any signal are random.
ADC Single Read mode The ADC should be configured before reading is taken.
• For ADC1, configure desired precision and attenuation by calling functions adc1_config_width() and
adc1_config_channel_atten().
• For ADC2, configure the attenuation by adc2_config_channel_atten(). The reading width of
ADC2 is configured every time you take the reading.
Attenuation configuration is done per channel, see adc1_channel_t and adc2_channel_t, set as a parameter
of above functions.
Then it is possible to read ADC conversion result with adc1_get_raw() and adc2_get_raw(). Reading
width of ADC2 should be set as a parameter of adc2_get_raw() instead of in the configuration functions.
Single Read mode ADC example can be found in peripherals/adc/single_read directory of ESP-IDF examples.
This API provides convenient way to configure ADC1 for reading from ULP. To do so, call function
adc1_ulp_enable() and then set precision and attenuation as discussed above.
There is another specific function adc_vref_to_gpio() used to route internal reference voltage to a GPIO pin.
It comes handy to calibrate ADC reading and this is discussed in section ADC Calibration.
Note: See ADC Limitations for the limitation of using ADC single read mode.
Espressif Systems 215
Submit Document Feedback
Release v4.4