Example Code for ESP32-E-Output Triangular Wave
The AD9837 module outputs a triangular wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.
Hardware Preparation
- ESP32-E (or similar) x 1
- AD9837 DDS Waveform Generator Module x1
- Jumper wires
- Oscilloscope x1
Software Preparation
- Arduino IDE
- Install SDK: click to check the SDK installtion tutorial on FireBeetle ESP32-E Wiki Page
- Download and install the DFRobot AD9837 Library. (About how to install the library?)
Wiring Diagram

Connection description
- AD9837 DAT to controller 23/MOSI
- AD9837 CLK to controller 18/SCK
- AD9837 FSC to controller 25/D2(ssPin in the code)
- AD9837 VCC to controller 3.3V
- AD9837 GND to controller GND
- AD9837 AGND to Oscilloscope GND
- AD9837 OUT to Oscilloscope Signal Input
Although AD9837 supports 3.3~5.5V, its power voltage should be consistent with the controller's level voltage. Since the level of FireBeetle ESP32-E is 3.3V, the VCC should be connected to 3V3. If connecting to maincontroller's VCC(VIN) pin, it will cause the AD9837 to misjudge the level, resulting in data error and output waveform error.`
Sample Code
/*
* Output triangular wave signal;
* The amplitude of triangular wave signal is about 0.645V;
*/
#include <DFRobot_AD9837.h>
uint8_t ssPin = D2;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI); //Init an instance. Call class interface by this instance
void setup(void)
{
AD9837.begin(/* frequency= */10000000);//Init SPI communication, frequency:SPI communication max frequency
AD9837.outputTriangle(/* phase= */0, /* freq= */1000.0);//Output phase 0, frequency 1KHz
}
void loop()
{
delay(100);
}
Result

Was this article helpful?
