MCP4725 is a single channel, 12-bit, voltage output Digital-to-Analog Converter with integrated EEPROM and an I2C Compatible Serial Interface.
Features
12-Bit Resolution
On-Board Non-Volatile Memory (EEPROM)
±0.2 LSB DNL (typ)
External A0 Address Pin
Normal or Power-Down Mode
Fast Settling Time of 6µs (typ)
External Voltage Reference (VDD)
Rail-to-Rail Output
Low Power Consumption
Single-Supply Operation: 2.7V to 5.5V
I2CTM Interface:
Eight Available Addresses
Standard (100 kbps), Fast (400 kbps) andHigh Speed (3.4 Mbps) Modes
Small 6-lead SOT-23 Package
Extended Temperature Range: -40°C to +125°C
As this is a 12 bit DAC converter. What this means is that it will accept up to 4096 possible inputs to provide an analog output, where an output value of zero is zero and an output value of 4095 is full scale.
Full scale is determined by the reference voltage you supply to the VCC pin. Also you can see from above that the supply voltage can be anywhere from 2.7 volts to 5.5 volts. We will use 5v, or as close as what is supplied via the USB in. You may want to measure this voltage for accurate readings, I've seen this vary.
This means that to work out the value of the Least Significant Bit (LSB) is as follows:
1 LSB = VCC Voltage / 4096
Again the easiest way to interface this to an Arduino is to purchase a module, tehse are available from many sources, here is what my one looked at.
The module has the ability to use different I2C addresses, so run the code from here first. My one was the default 0x60 address
Code
This code example uses the Adafruit library, in the most recent (1.6.5 onwards) Arduino IDE you can import this using Include Libraries -> Manage Libraries. Basically we increment the DAC, read in the value and display the results
[codesyntax lang=”cpp”]
#include <Wire.h> #include <Adafruit_MCP4725.h> #define MCP4725In A0 Adafruit_MCP4725 MCP4725; void setup(void) { Serial.begin(9600); MCP4725.begin(0x60); // The I2C Address of my module } void loop(void) { uint32_t MCP4725_value; int adcInput = 0; float voltageIn = 0; float MCP4725_reading; for (MCP4725_value = 0; MCP4725_value < 4096; MCP4725_value = MCP4725_value + 128) { MCP4725_reading = (5.0/4096.0) * MCP4725_value; //5.0 is your supply voltage MCP4725.setVoltage(MCP4725_value, false); delay(250); adcInput = analogRead(MCP4725In); //module output connect to A0 voltageIn = (adcInput * 5.0 )/ 1024.0; Serial.print("\tExpected Voltage: "); Serial.print(MCP4725_reading,3); Serial.print("\tArduino Voltage: "); Serial.println(voltageIn,3); } }
[/codesyntax]
Links
MCP4725 I2C DAC Breakout Development Board 12Bit Resolution