class DAC – digital to analog conversion
The DAC is used to output an analog voltage based on a digital value.
The output voltage will be between 0 and 3.3V.
DAC is currently supported on ESP32 [1], SAMD and Renesas RA.
Note
The STM32 port has similar functionality to machine.DAC. See
pyb.DAC for details.
Example usage (ESP32):
from machine import DAC
dac = DAC(pin) # create a DAC object acting on a pin
dac.write(128) # write a value to the DAC
dac.write(255) # output maximum value, 3.3V
Constructors
- class machine.DAC(id)
Construct a new DAC object.
idis a pin object (ESP32 and Renesas RA) or an index to a DAC resource (SAMD).
Note
On the ESP32, DAC functionality is available on pins 25 and 26. On the ESP32-S2, pins 17 and 18. See ESP32 Quickref for more details.
Note
SAMD21 has one DAC resource, SAMD51 has two. See SAMD Quickref for more details.
Methods
- DAC.write(value)
Output an analog voltage to the pin connected to the DAC.
valueis a representation of the desired output; a linear interpolation of 0-3.3V, though the range differs depending on the port and micro, see below:Port/micro
Bits
Range
ESP32
8
0-255
SAMD21
10
0-1023
SAMD51
12
0-4095
Renesas RA
12
0-4095
Footnotes