Memorial day is 05/25/2015 – Orders will ship out on May 26th. There will not be any deliveries or shipping on Monday. Any order placed after 11am ET on Friday May 22nd will not start to ship out until Tuesday May 26th.

Using with Arduino

Author Gravatar Image LADY ADA

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

To download it, visit the GitHub repository and click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_MCP4725. Check that the Adafruit_MCP4725 folder contains Adafruit_MCP4725.cpp and Adafruit_MCP4725.h 

Place the Adafruit_MCP4725 library folder your sketchbookfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. You can figure out your sketchbookfolder by opening up the Preferences tab in the Arduino IDE.

  Restart the IDE.

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)

We also have a sine wave version showing how to use a lookup table to create a more complex waveform.

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 TWBR
TWBR = 12; // 400 khz
You can speed this up a bit more, if you'd like, check the ATmega328 datasheet for how to calculate the TWBR register.
Last updated on 2015-05-04 at 04.27.56 PM Published on 2012-09-05 at 04.30.16 PM