#include <Wire.
h>//Include the Wire library to talk I2C
//This is the I2C Address of the MCP4725, by default (A0 pulled to GND).
//Please note that this breakout is for the MCP4725A0.
#define MCP4725_ADDR 0x60
//For devices with A0 pulled HIGH, use 0x61
//Sinewave Tables were generated using this calculator:
//[Link]
int lookup = 0;//varaible for navigating through the tables
int sintab2[512] =
{
2048, 2073, 2098, 2123, 2148, 2174, 2199, 2224 };
void setup()
{
[Link]();
// Set A2 and A3 as Outputs to make them our GND and Vcc,
//which will power the MCP4725
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
digitalWrite(A2, LOW);//Set A2 as GND
digitalWrite(A3, HIGH);//Set A3 as Vcc
}
//---------------------------------------------------
void loop()
{
[Link](MCP4725_ADDR);
[Link](64); // cmd to update the DAC
[Link](sintab2[lookup] >> 4); // the 8 most significant bits...
[Link]((sintab2[lookup] & 15) << 4); // the 4 least significant bits...
[Link]();
lookup = (lookup + 1) & 511;
}
To give more power to Arduino board DAC (Digital to Analog
Converter) interfaced through breakout board and detailed Arduino
DAC Tutorial given in this article for the best understanding. Here
DAC IC MCP4725 based breakout board is used because it is 12-Bit
Digital-to-Analog Converter with EEPROM Memory, this IC utilize low
power and gives high accuracy output. This IC comes in sot package
hence better to go with breakout board in this tutorial we used
Sparkfun I2C Breakout MCP4725 board. By using this board we can
obtain Analog voltage from Arduino board depends on the digital input
and it accepts input in I2C format.
MCP4725 DAC IC
Features and Applications of MCP4725. This IC provides 12 bit
resolution and on board Board Non-Volatile Memory (EEPROM). It
can be addressed by external A0 address pin, and operates in Normal
or Power-Down Mode. It takes wide range of input supply voltage as
2.7V to 5.5V from single supply source. This IC provides eight address
through I2C and have Extended Temperature Range: -40°C to
+125°C.
Applications
Sensor Calibration
PC Peripherals
Data Acquisition Systems
Low Power Portable Instrumentation
MCP4725 Arduino connection
Construction & Working. Connect 5V pin and GND pin of Arduino
board to Breakout board VCC and GND pin then connect A4 (SDA),
A5 (SCL) pins with corresponding I2C pin of MCP 4725 brakout board.
If you using other Arduino board then refer and use the corresponding
I2C pins. Output pin of MCP4725 is connected with Analog pin A0 by
the way we can measure and display the Analog voltage obtained
from MCP4725 in serial monitor, you can also measure by using
digital voltmeter or multimeter.
Arduino MCP4725 Code
Here is an example code for the MCP4725 with the Arduino. You will
need to install the Adafruit_MCP4725.h library so downlaod it from
below. It will be [Link] file. In Arduino IDE, go to include library as .zip
file and select the downlaoded file. Now the library shoudl work.
Compile, make the connections and uplaod the code.
Download Adafruit_MCP4725.h
#include <Wire.h> //wire library
#include <Adafruit_MCP4725.h> // MCP4725 library from adafruit
#define analogVin A0 // Analog voltage input to A0
Adafruit_MCP4725 MCP4725;
void setup(void) {
[Link](9600);
[Link](0x60); // Default I2C Address of MCP4725 breakout board (sparkfun)
If not try 0x61 or 0x62
void loop(void) {
uint32_t MCP4725_value;
int adcValueRead = 0;
float voltageRead = 0;
float MCP4725_expected_output;
for (MCP4725_value = 0; MCP4725_value < 4096; MCP4725_value = MCP4725_value + 15)
{
MCP4725_expected_output = (5.0/4096.0) * MCP4725_value;
[Link](MCP4725_value, false);
delay(250);
adcValueRead = analogRead(analogVin);
voltageRead = (adcValueRead * 5.0 )/ 1024.0;
[Link]("MCP4725 Value: ");
[Link](MCP4725_value);
[Link]("\tExpected Voltage: ");
[Link](MCP4725_expected_output,3);
[Link]("\tArduino ADC Value: ");
[Link](adcValueRead);
[Link]("\tArduino Voltage: ");
[Link](voltageRead,3);
}
}