Arduino - function generator

what is it

This is a simple function generator.

Using nothing more than an MCP4725 DAC and an Arduino, this program generates sinusses, triangles, etc. with a configurable offset and amplitude.

how to use it

After flashing the program to the Arduino (e.g. Nano), connect to it using a serial-terminal. That gives you a menu with which you can set it up.
Press '?' to get a list of options.

what does it look like

This screendump shows how it looks like running from putty under windows:


Plotted with OpenHantek oscilloscope:

Allan deviation:

To plot this graph, I connected the function generator in "square wave"-mode to a comparer with the source being the PPS signal of a Adafruit GPS shield. The output of the comparer is fed to TimeLab which produces the plot seen above (TimeLab runs fine under Linux using Wine).

code & schematics


Download: funcgen.ino

This requires you to have installed either the Arduino IDE or e.g. arduino-mk.


It basically is: connect the VCC/GND of the MCP4725 to the same pins on the Arduino. Then SCL to A5 and SDA to A4 on the Arduino.

The "out"-pin on the MCP4725 emits the generated signal (0...5V - this depends on the voltage of VCC, see below). So connect that one together with the GND-pin next to it to whatever you want to give the signal to.

changing signal levels

The MCP4725 produces a signal that is in the range of its VCC. So the case of an Arduino that is 0V upto 5V. If you want to change that, you can add an op amp. On this page you can calculate the values of the resistors that need to be connected to it. And here you'll find an example for converting the signal into -2...+2V.


It uses code from several