Digital To Analog Converter

Overview

ESP32 has two 8-bit DAC (digital to analog converter) channels, connected to GPIO25 (Channel 1) and GPIO26 (Channel 2).

The DAC driver allows these channels to be set to arbitrary voltages.

The DAC channels can also be driven with DMA-style written sample data, via the I2S driver when using the “built-in DAC mode”.

For other analog output options, see the Sigma-delta Modulation module and the LED Control module. Both these modules produce high frequency PWM output, which can be hardware low-pass filtered in order to generate a lower frequency analog output.

Application Example

Setting DAC channel 1 (GPIO 25) voltage to approx 0.78 of VDD_A voltage (VDD * 200 / 255). For VDD_A 3.3V, this is 2.59V:

#include <driver/dac.h>

...

    dac_out_voltage(DAC_CHANNEL_1, 200);

API Reference

Header Files

  • components/driver/include/driver/dac.h

Enumerations

enum dac_channel_t

Values:

DAC_CHANNEL_1 = 1

DAC channel 1 is GPIO25

DAC_CHANNEL_2

DAC channel 2 is GPIO26

DAC_CHANNEL_MAX

Functions

esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value)

Set DAC output voltage.

DAC output is 8-bit. Maximum (255) corresponds to VDD.

Note
When this function is called, function for the DAC channel’s GPIO pin is reconfigured for RTC DAC function.
Return
  • ESP_OK success
  • ESP_ERR_INVALID_ARG Parameter error
Parameters
  • channel: DAC channel
  • dac_value: DAC output value