The DAC is used to output analog values (a specific voltage) on pin P22 or pin P21. The voltage will be between 0 and 3.3V.
P22
P21
0
3.3V
import machine dac = machine.DAC('P22') # create a DAC object dac.write(0.5) # set output to 50% dac_tone = machine.DAC('P21') # create a DAC object dac_tone.tone(1000, 0) # set tone output to 1kHz
Create a DAC object, that will let you associate a channel with a pin. pin can be a string argument.
pin
Enable the DAC block. This method is automatically called on object creation.
Disable the DAC block.
Set the DC level for a DAC pin. value is a float argument, with values between 0 and 1.
value
Sets up tone signal to the specified frequency at amplitude scale. frequency can be from 125Hz to 20kHz in steps of 122Hz. amplitude is an integer specifying the tone amplitude to write the DAC pin. Amplitude value represents:
frequency
amplitude
125Hz
20kHz
122Hz
1
2
3
The generated signal is a sine wave with an DC offset of VDD/2.