# MCP4725 12-Bit DAC Tutorial

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/108/811/medium800/adafruit_products_MCP4725_top.jpg?1644356800)

Your microcontroller probably has an ADC (analog -\> digital converter) but does it have a DAC (digital -\> analog converter)??? Now it can! This breakout board features the easy-to-use MCP4725 12-bit DAC. Control it via I2C and send it the value you want it to output, and the VOUT pin will have it. Great for audio / analog projects, such as when you can't use PWM but need a sine wave or adjustable bias point.  
  
We break out the ADDR/A0 pin so you can connect two of these DACs on one I2C bus, just tie that pin of one high (or close the jumper on the back) to keep it from conflicting. Also included is a 6-pin header, for use in a breadboard. Works with both 3.3V or 5V logic.

![](https://cdn-learn.adafruit.com/assets/assets/000/108/814/medium800/adafruit_products_MCP4725_back.jpg?1644357350)

Some nice extras with this chip: for chips that have 3.4Mbps Fast Mode I2C (Arduino's don't) you can update the Vout at ~200 KHz. There's an EEPROM so if you write the output voltage, you can 'store it' so if the device is power cycled it will restore that voltage. The output voltage is rail-to-rail and proportional to the power pin so if you run it from 3.3V, the output range is 0-3.3V. If you run it from 5V the output range is 0-5V.  
  
[We have an easy-to-use Arduino and CircuitPython/Python library and tutorial with a triangle-wave and sine-wave output example](http://learn.adafruit.com/mcp4725-12-bit-dac-tutorial) that can be used with just about any microcontroller or microcomputer with I2C host.

![](https://cdn-learn.adafruit.com/assets/assets/000/108/813/medium800/adafruit_products_MCP4725_top_header.jpg?1644357341)

Comes with a bit of 0.1" standard header in case you want to use it with a breadboard or perfboard.&nbsp; Four mounting holes for easy attachment. There's an _optional_ 3.5mm terminal block spot on the PCB - [we don't include a 3.5mm terminal block but they're both common and stocked in the shop](https://www.adafruit.com/product/724) - that you can solder in place if you like.

![](https://cdn-learn.adafruit.com/assets/assets/000/108/812/medium800/adafruit_products_MCP4725_STEMMA_side.jpg?1644357334)

To get you going fast, we spun up a custom-made PCB in the[&nbsp; **STEMMA QT** &nbsp;form factor](https://www.adafruit.com/?q=stemma%20qt%20sensor "STEMMA QT form factor"), making it easy to interface with. The&nbsp;[STEMMA QT connectors](https://learn.adafruit.com/introducing-adafruit-stemma-qt/what-is-stemma-qt)&nbsp;on either side are compatible with the&nbsp;[SparkFun Qwiic](https://www.sparkfun.com/qwiic)&nbsp;I2C connectors. This allows you to make solderless connections between your development board and the MCP4725 or to chain it with a wide range of other sensors and accessories using a&nbsp;[**compatible cable**](https://www.adafruit.com/?q=stemma%20qt%20cable).

[**QT Cable is not included** , but we have a variety in the shop](https://www.adafruit.com/?q=stemma+qt+cable&sort=BestMatch).&nbsp;

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/036/264/medium800/components_935-04.jpg?1475857965)

# MCP4725 12-Bit DAC Tutorial

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/108/829/medium800/adafruit_products_MCP4725_pinouts.jpg?1644426465)

The default I2C address is **0x62**.

# Power Pins

The sensor on the breakout requires between a 2.7V and 5.5V, and can be easily used with most microcontrollers from an Arduino to a Feather or something else.

- **VIN** - this is the power pin.&nbsp; To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
- **GND** - common ground for power and logic

## I2C Logic Pins

- **SCL** - I2C clock pin, connect to your microcontroller's I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a **10K pullup** on this pin.
- **SDA** -I2C data pin, connect to your microcontroller's I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a 1 **0K pullup** on this pin.
- [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) **-** These connectors allow you to connect to development boards with **STEMMA QT** connectors, or to other things, with[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204).

## Other Pins

- **A0 pin / ADDR jumper** - Tie A0 high, or close the jumper on the back to change the I2C address to **0x63** , so you can connect two MCP4725 breakouts on the same I2C bus.
- **VOUT** - This is the output pin for the I2C signal.
- **Optional terminal block** - There is an optional 3.5mm terminal block spot on the board that breaks out **VOUT** and **GND**. You can solder a terminal block on if you like. The terminal block does not come with the board, but they are common and you can [purchase one from the Adafruit shop](https://www.adafruit.com/product/724).

# MCP4725 12-Bit DAC Tutorial

## Arduino Wiring

Wiring up the MCP4725 breakout PCB is super easy. To start, we'll attach the breakout headers so we can plug it into a breadboard.  
  
Break off a strip of 6-pins of 0.1" male header and stick the LONG pins down into a breadboard

Break off a strip of 6-pins of 0.1" male header and stick the LONG pins down into a breadboard

![components_headerdown.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/005/medium640/components_headerdown.jpg?1396778191)

Place the breakout board on top so the short ends of the header stick up through the pads

![components_place.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/006/medium640/components_place.jpg?1396778201)

Solder each pin using a soldering iron and solder, to make solid connection on each pin.  
  
This part is not optional! You cannot 'press fit' the header on, it must be attached permanently

![components_solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/007/medium640/components_solder.jpg?1396778211)

![components_soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/002/009/medium640/components_soldered.jpg?1396778218)

Now that the header is attached, we can wire it up. We'll demonstrate using an Arduino

- **Breakout VDD (power)** to **5V** if your microcontroller is 5V logic, or to 3V if your micro is 3V logic **(red wire on STEMMA QT version)**  
- **Breakout GND** to **microcontroller GND (black wire on STEMMA QT version)**  
- **Breakout SDA** to **microcontroller** **I2C Data (blue wire on STEMMA QT version)** (on the Uno, this is **A4** on the Mega it is&nbsp; **20&nbsp;** and on the Leonardo digital&nbsp; **2** )
- **Breakout SCL** &nbsp; to **microcontroller I2C Clock (yellow wire on STEMMA QT version)** (on the Uno, this is **A5** on the Mega it is&nbsp; **21&nbsp;** and on the Leonardo digital&nbsp; **3** )

![adafruit_products_MCP4725_Arduino_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/833/medium640/adafruit_products_MCP4725_Arduino_STEMMA_bb.jpg?1644427971)

![adafruit_products_MCP4725_Arduino_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/834/medium640/adafruit_products_MCP4725_Arduino_breadboard_bb.jpg?1644427994)

![adafruit_products_MCP4725_Arduino_original.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/835/medium640/adafruit_products_MCP4725_Arduino_original.jpg?1644428034)

There's two other pins remaining.

- **A0** allow you to change the I2C address. By default (nothing attached to A0) the address is hex **0x62**. If A0 is connected to **VDD** the address is **0x63**. This lets you have two DAC boards connected to the same SDA/SCL I2C bus pins.
- **VOUT** is the voltage out from the DAC! The voltage will range from 0V (when the DAC value is 0) to VDD (when the DAC 'value' is the max 12-bit number: 0xFFF)

# MCP4725 12-Bit DAC Tutorial

## Arduino Code

## Library Installation

Once wired up, to start using the MCP4725, you'll need to install the [Adafruit\_MCP4725 library](https://github.com/adafruit/Adafruit_MCP4725). The library is available through the Arduino library manager so we recommend taking that approach.

From the Arduino IDE, open up the Library Manager:

![Library](https://cdn-learn.adafruit.com/assets/assets/000/085/942/medium640/adafruit_products_library_manager_menu.png?1576653625 )

Click the&nbsp; **Manage Libraries ...** &nbsp;menu item, search for&nbsp; **Adafruit MCP4725** ,&nbsp;and select the&nbsp; **Adafruit MCP4725** library and click **Install** :

![](https://cdn-learn.adafruit.com/assets/assets/000/115/469/medium800/adafruit_products_libman.png?1664474067)

Next up, download the Adafruit MCP4725 library. This library does all of the interfacing, so you can just "set and forget" the DAC&nbsp;output. It also has some examples to get you started

[The library is available on GitHub](https://github.com/adafruit/Adafruit_MCP4725). You can download it by clicking the button below.

[Download Adafruit_MCP4725 Library](https://github.com/adafruit/Adafruit_MCP4725/archive/master.zip)
## 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)

![](https://cdn-learn.adafruit.com/assets/assets/000/002/016/medium800/components_ID935trace_LRG.jpg?1396778266)

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.  
# MCP4725 12-Bit DAC Tutorial

## Python & CircuitPython

It's easy to use the MCP4725 digital to analog converter with Python and CircuitPython, and the&nbsp;[Adafruit CircuitPython MCP4725](https://github.com/adafruit/Adafruit_CircuitPython_MCP4725)&nbsp;module.&nbsp; This module allows you to easily write Python code that controls the output voltage from the DAC.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

# CircuitPython Microcontroller Wiring

First wire up a MCP4725 to your board exactly as shown on the previous pages for Arduino using an I2C connection. &nbsp;Here's an example of wiring a Feather M0 to the sensor with I2C:

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (red wire on STEMMA QT version)**  
- **Board GND** &nbsp;to&nbsp;**sensor GND (black wire on STEMMA QT version)**  
- **Board SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire on STEMMA QT version**  
- **Board SDA** &nbsp;to&nbsp;**sensor SDA (blue wire on STEMMA QT version**  

![adafruit_products_MCP4725_Feather_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/836/medium640/adafruit_products_MCP4725_Feather_STEMMA_bb.jpg?1644428393)

![adafruit_products_MCP4725_Feather_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/837/medium640/adafruit_products_MCP4725_Feather_breadboard_bb.jpg?1644428423)

![adafruit_products_MCP4725_Feather_original.png](https://cdn-learn.adafruit.com/assets/assets/000/108/838/medium640/adafruit_products_MCP4725_Feather_original.png?1644428468)

# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V3** to **sensor VIN (red wire on STEMMA QT version)**  
- **Pi GND** to **sensor GND (black** **wire on STEMMA QT version)**
- **Pi SCL** to **sensor SCL (yellow wire on STEMMA QT version)**   
- **Pi SDA** to **sensor SDA (blue wire on STEMMA QT version)**  

![adafruit_products_MCP4725_RasPi_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/842/medium640/adafruit_products_MCP4725_RasPi_STEMMA_bb.jpg?1644429966)

![adafruit_products_MCP4725_RasPi_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/843/medium640/adafruit_products_MCP4725_RasPi_breadboard_bb.jpg?1644429990)

![adafruit_products_MCP4725_RasPi_original.jpg](https://cdn-learn.adafruit.com/assets/assets/000/108/844/medium640/adafruit_products_MCP4725_RasPi_original.jpg?1644430011)

# CircuitPython Installation of MCP4725 Library

Next you'll need to install the&nbsp;[Adafruit CircuitPython MCP4725](https://github.com/adafruit/Adafruit_CircuitPython_MCP4725)&nbsp;library on your CircuitPython board. &nbsp;Make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://github.com/adafruit/circuitpython/releases)&nbsp;for your board before starting..

You'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).&nbsp; For example the Circuit Playground Express guide has&nbsp;[a great page on how to install the library bundle](../../../../adafruit-circuit-playground-express/installing-libraries)&nbsp;for both express and non-express boards.

Remember for non-express boards like the Trinket M0, Gemma M0, and Feather/Metro M0 basic you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_mcp4725.mpy**

You can also download the&nbsp; **adafruit\_mcp4725.mpy** &nbsp;from&nbsp;[its releases page on Github](https://github.com/adafruit/Adafruit_CircuitPython_MCP4725/releases).

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_mcp4725.mpy**** &nbsp; **file** &nbsp;**copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](../../../../micropython-basics-how-to-load-micropython-on-a-board/serial-terminal)so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# Python Installation of MCP4725 Library

You'll need to install the Adafruit\_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. [Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-mcp4725`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

# CircuitPython & Python Usage

To demonstrate the usage of the DAC we'll initialize it and set the output voltage from the board's Python REPL. &nbsp;Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

```auto
import board
import busio
import adafruit_mcp4725
i2c = busio.I2C(board.SCL, board.SDA)
dac = adafruit_mcp4725.MCP4725(i2c)
```

Now you can set the output voltage just like controlling a DAC with CircuitPython's built-in AnalogOut class and the **value** property. &nbsp;Simply set this to any 16-bit value (0-65535) and the output of the Vout pin will change to a voltage proportional to 0-3.3V. &nbsp;For example to set the output to 1.65V or about halfway within its range:

```auto
dac.value = 32767
```

Hook up a multimeter to the **Vout** pin of the board (positive/red lead to **Vout** , ground/black lead to board GND) and you should see about 1.65 volts DC output. &nbsp;Try setting **dac.value** to other numbers like 0 or 65535 to see how the voltage changes.

![adafruit_products_IMG_20180202_163122823.jpg](https://cdn-learn.adafruit.com/assets/assets/000/059/022/medium640/adafruit_products_IMG_20180202_163122823.jpg?1533921681)

Hook up a multimeter to the **Vout** pin of the board (positive/red lead to **Vout** , ground/black lead to board GND) and you should see about 1.65 volts DC output. &nbsp;Try setting **dac.value** to other numbers like 0 or 65535 to see how the voltage changes.

You can use the MCP4725 instance anywhere you might use the AnalogOut class!

However you might prefer a few other simpler properties to change the output voltage:

- **normalized\_value** - Set this to a floating point number between 0 and 1.0. &nbsp;A value of 0 is ground/0V and 1.0 is Vdd or max voltage/3.3V. &nbsp;Anything in-between is a proportional voltage. &nbsp;This is handy for scaling the output value without having to worry about how many bits of resolution it has.
- **raw\_value** - Set this to a 12-bit value 0-4095 to control the raw 12-bit output of the DAC. &nbsp;Unlike the **value** property this **raw\_value** exposes the true 12-bit resolution of the DAC and is free from quantization errors. &nbsp;If you need the most precise output use the raw\_output value for setting voltage.

```auto
dac.normalized_value = 0.5  # ~1.65V output
dac.raw_output = 2047 # Also ~1.65V output
```

That's all there is to using the MCP4725 DAC with CircuitPython!

Below is a complete example that shows changing the DAC voltage to a triangle wave that goes up and down repeatedly. &nbsp;Save this as **code.py** on your board and connect a multimeter to measure the Vout pin voltage to see it oscillate up and down from 0 to 3.3V and back.

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_MCP4725/blob/main/examples/mcp4725_simpletest.py

# MCP4725 12-Bit DAC Tutorial

## Python Docs

# MCP4725 12-Bit DAC Tutorial

## Downloads

# Files

- [For more details about the chip, please check out the MCP4725 datasheet](http://www.adafruit.com/datasheets/mcp4725.pdf "Link: http://www.adafruit.com/datasheets/mcp4725.pdf")
- [MCP4725 Arduino Library is on GitHub](https://github.com/adafruit/Adafruit_MCP4725 "Link: https://github.com/adafruit/Adafruit\_MCP4725")
- [Fritzing object in the Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-MCP4725-PCB)

# Schematic & Fabrication Print STEMMA QT Version
![](https://cdn-learn.adafruit.com/assets/assets/000/108/830/medium800/adafruit_products_MCP4725_sch.png?1644427046)

![](https://cdn-learn.adafruit.com/assets/assets/000/108/832/medium800/adafruit_products_MCP4725_fab_print.png?1644427148)

# Schematic & Fabrication Print Original Version
![](https://cdn-learn.adafruit.com/assets/assets/000/036/265/medium800/components_schem.png?1475858229)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/266/medium800/components_fabprint.png?1475858244)


## Featured Products

### MCP4725 Breakout Board - 12-Bit DAC with I2C Interface

[MCP4725 Breakout Board - 12-Bit DAC with I2C Interface](https://www.adafruit.com/product/935)
Your microcontroller probably has an ADC (analog -\> digital converter) but does it have a DAC (digital -\> analog converter)??? Now it can! This breakout board features the easy-to-use MCP4725 12-bit DAC. Control it via I2C and send it the value you want it to output, and the VOUT pin...

In Stock
[Buy Now](https://www.adafruit.com/product/935)
[Related Guides to the Product](https://learn.adafruit.com/products/935/guides)

## Related Guides

- [CircuitPython MIDI to CV Skull](https://learn.adafruit.com/circuitpython-midi-to-cv-skull.md)
- [MCP4725 12-Bit DAC with Raspberry Pi](https://learn.adafruit.com/mcp4725-12-bit-dac-with-raspberry-pi.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Experimenter's Guide for Metro](https://learn.adafruit.com/experimenters-guide-for-metro.md)
- [Analog Devices ADXL343 Breakout Learning Guide](https://learn.adafruit.com/adxl343-breakout-learning-guide.md)
- [ST 9-DoF Combo Breakouts and Wings](https://learn.adafruit.com/st-9-dof-combo.md)
- [Adafruit I2S Amplifier BFF](https://learn.adafruit.com/i2s-amplifier-bff.md)
- [RP2040 RunCPM Emulator with USB Keyboard & HDMI screen](https://learn.adafruit.com/rp2040-runcpm-emulator-with-usb-keyboard-hdmi-screen.md)
- [Adafruit Feather 32u4 Basic Proto](https://learn.adafruit.com/adafruit-feather-32u4-basic-proto.md)
- [Adafruit Metro M7 1011 with AirLift](https://learn.adafruit.com/adafruit-metro-m7-with-airlift.md)
- [Adafruit AirLift - ESP32 WiFi Co-Processor Breakout](https://learn.adafruit.com/adafruit-airlift-breakout.md)
- [Adafruit HUZZAH ESP8266 breakout](https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout.md)
- [FeatherWing Proto, Doubler  and Tripler](https://learn.adafruit.com/featherwing-proto-and-doubler.md)
- [Adafruit SensorLab - Gyroscope Calibration](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration.md)
- [Adafruit RS-232 Full Pinout Level-Shifter Breakout](https://learn.adafruit.com/adafruit-rs-232-full-pinout-level-shifter-breakout.md)
