Example Code for Arduino UNO-Output Sinusoidal Wave
The AD9837 module outputs a sinusoidal 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
- DFRuino UNO R3 (or similar) x 1
- AD9837 DDS Waveform Generator Module x1
- Jumper wires
- Oscilloscope x1
Software Preparation
- Arduino IDE
- Download and install the DFRobot AD9837 Library. (About how to install the library?)
Wiring Diagram

Connection description
- AD9837 DAT to controller 11/MOSI
- AD9837 CLK to controller 13/SCK
- AD9837 FSC to controller pin 5 (ssPin in the code)
- AD9837 VCC to controller 5V
- 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 5V, the VCC should be connected to 5V. If connecting to UNO's 3V3, it will cause the AD9837 to misjudge the level, resulting in data error and output waveform error.`
Sample Code
/*
* Output sinusoidal wave signal;
* The amplitude of sinusoidal wave signal is about 0.645V;
*/
#include <DFRobot_AD9837.h>
uint8_t ssPin = 5;
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.outputSin(/* phase= */0, /* freq= */1000.0); //Output sinusoidal wave with phase 0 and frequency 1KHz
}
void loop()
{
delay(100);
}
Result

Was this article helpful?
