-
Notifications
You must be signed in to change notification settings - Fork 344
dac
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.<br The DAC channels can also be driven with DMA-style written sample data, via the I2S driver when using the “built-in DAC mode”.
This class includes full support for using ESP32 DAC peripheral.
ESP32 DAC output voltage range is 0-Vdd (3.3 V), the resolution is 8-bits
pin
argument defines the gpio which will will be used as dac output.
Only GPIOs 25 and 26 can be used as DAC outputs.
The pin
argument can be given as pin number (integer) or the machine.Pin
object.
>>> import machine
>>> dac=machine.DAC(25)
>>> dac
DAC(Pin(25), channel: 1)
>>>
Set the DAC value. Valid range is: 0 - 255
The value of 255 sets the voltage on dac pin to 3.3 V
Generate the waveform on the dac output
Arg | Description |
---|---|
freq |
the waveform frequency; valid range: 16-32000 Hz for sine wave 500-32000 Hz for noise 170 - 3600 Hz for triangle 170 - 7200 Hz for ramp and sawtooth |
type |
the waveform type, use one of the defined constants:SINE , TRIANGLE , RAMP , SAWTOOTH and NOISE
|
duration |
optional, is given, waits for duration ms and stops the waveform |
scale |
optional, only valid for sine wave; range: 0-3; scale the output voltage by 2^scale
|
offset |
optional, only valid for sine wave; range: 0-255; ofset the output voltage by offset value |
invert |
optional, only valid for sine wave; range: 0-3; invert the half-cycle of the sine wave |
Generate the sine wave beep on the dac output
Arg | Description |
---|---|
freq |
fequency; valid range: 16-32000 Hz |
duration |
the duration of the beep in ms |
scale |
optional; range: 0-3; scale the output voltage by 2^scale
|