Library Installation
Once wired up, to start using the MCP4725, you'll need to install the Adafruit_MCP4725 library. The library is available through the Arduino library manager so we recommend taking that approach.
From the Arduino IDE, open up the Library Manager:

Click the Manage Libraries ... menu item, search for Adafruit MCP4725, and select the Adafruit MCP4725 library and click Install:
Next up, download the Adafruit MCP4725 library. This library does all of the interfacing, so you can just "set and forget" the DAC output. It also has some examples to get you started
The library is available on GitHub. You can download it by clicking the button below.
Triangle Wave Example
Open up the File→Examples→Adafruit_MCP4725→trianglewave sketch and upload it to the Arduino. Then connect your oscilloscope (or an LED + resistor if you don't have access to an oscilloscope)
Using the library
The library is very simple, so you can adapt it very quickly.First, be sure to call begin(addr) where addr is the i2c address (default is 0x62, if A0 is connected to VCC its 0x63). Then call setVoltage(value, storeflag) to set the DAC output. value should range from 0 to 0x0FFF. storeflag indicates to the DAC whether it should store the value in EEPROM so that next time it starts, it'll have that same value output. You shouldn't set the flag to true unless you require it as it will take longer to do, and you could wear out the EEPROM if you write it over 20,000 times.
Increasing the speed
One thing thats a little annoying about the Arduino Wire library in this case is it is set for 100KHz transfer speed. In the MCP4725 library we update the speed to 400KHz by setting the TWBRTWBR = 12; // 400 khzYou can speed this up a bit more, if you'd like, check the ATmega328 datasheet for how to calculate the TWBR register.
Page last edited March 08, 2024
Text editor powered by tinymce.