The AD9833 is a Direct Digital Synthesizer that can generate sine, square or triangle waves and is controlled using the SPI protocol. Since the device is in an MSOP package the easiest way to use it is by getting yourself a breakout board. You can buy two types, one comes with an opamp buffer chip and digital attenuator for adjusting the output level. The reason that the opamp is needed is that the output of the AD9833 is about 600mV. The opamp amplifies the signal by 5 to give a 3V output. Using the digital pot allows you to reduce this output to a level you need.
Libraries:
AD9833 Basic:
For help type '?' into the send box in the Arduino Serial Monitor.
Typing the following commands outputs a 1kHz waveform to Vout
#include <MD_AD9833.h>
#include <SPI.h>
// Pins for SPI comm with the AD9833 IC
#define DATA 11 ///< SPI Data pin number
#define CLK 13 ///< SPI Clock pin number
#define FSYNC 10 ///< SPI Load pin number (FSYNC in AD9833 usage)
MD_AD9833 AD(FSYNC); // Hardware SPI
// MD_AD9833 AD(DATA, CLK, FSYNC); // Arbitrary SPI pins
void setup(void)
{
AD.begin();
}
void loop(void)
{
static uint16_t lastv = 0;
uint16_t v = analogRead(A0);
if (abs(v-lastv) > 20)
{
AD.setFrequency(MD_AD9833::CHAN_0, 1000 + v);
lastv = v;
}
}