Source: https://mokxi.com/libraries/adafruit-mcp4725
Updated: 2026-11-22

Libraries / Sensors

Arduino library · Sensors

# Adafruit MCP4725: a 12-bit analog output over I2C

Yes. You can use the Adafruit MCP4725 library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (DAC, MCP4725). The example below, "Set a voltage with the MCP4725 and read it back on A0", runs on the Arduino Uno R3.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <Adafruit_MCP4725.h> and it builds, with nothing to install. Free, and no account needed.

## What Adafruit MCP4725 does

An Uno’s analogWrite() is PWM, a square wave that only becomes a voltage after a filter. The MCP4725 is a real digital-to-analog converter on a small I2C board. Send it a number from 0 to 4095 and its VOUT pin holds that fraction of the supply voltage: on a 5 V supply, 1024 gives 1.25 V and each step is about 1.2 mV.

The library has two calls. begin() checks the chip acknowledges, and setVoltage(code, writeEEPROM) sends a value. Despite the name, setVoltage() takes the 12-bit code, not volts. Passing true as the second argument also stores the code in the chip’s EEPROM, so VOUT starts at that level after the next power-up; the chip is then busy for about 25 ms and ignores further writes, so keep EEPROM writes out of loops.

The address catches most people. The library defaults to 0x62, the address of Adafruit’s board, while the generic purple boards answer at 0x60, so call begin(0x60) for those, as the example does. Mokxi’s mcp4725 part follows the same rule, or set its model to MCP4725A1 to put it at 0x62. The example wires VOUT back to A0 so that analogRead() confirms each step of the voltage.

Library Manager name | Adafruit MCP4725

Author | Adafruit

Include | #include <Adafruit_MCP4725.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | DAC, MCP4725

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_MCP4725.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit MCP4725" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit MCP4725 to lib_deps in PlatformIO. Mokxi follows the calls of release 2.0.2, so a sketch written here builds there too.

What to know in the simulator: The library defaults to 0x62, Adafruit’s board (the MCP4725A1). The generic boards are 0x60: call begin(0x60), or set the part’s model to MCP4725A1.

- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- ESP32-S3-CAM
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### Adafruit_MCP4725 dac

Creates the driver; nothing is sent until begin().

### dac.begin(0x60)

Checks that a chip acknowledges at 0x60 and returns false otherwise. With no argument it uses 0x62.

### dac.setVoltage(2048, false)

Sets VOUT to 2048/4096 of the supply, half of it, without touching the EEPROM. Returns whether the chip acknowledged.

### dac.setVoltage(1024, true)

Sets the output and also stores 1024 as the power-up value. The chip ignores writes for about 25 ms afterward.

### dac.setVoltage(code, false, 100000)

The third argument is the I2C clock for the transfer, 400000 by default. Lower it for long wires.

## Example: Set a voltage with the MCP4725 and read it back on A0

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A0 to DAC, MCP4725 VOUT
- Arduino Uno R3 A4 to DAC, MCP4725 SDA
- Arduino Uno R3 A5 to DAC, MCP4725 SCL
- Arduino Uno R3 5V to DAC, MCP4725 VCC
- Arduino Uno R3 GND to DAC, MCP4725 GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### MCP4725 not found

begin() got no acknowledge at the address tried. Generic boards are at 0x60 and Adafruit’s at 0x62, which is the default; run an I2C scanner and pass whatever it finds to begin().

### VOUT stays near 0 V after setVoltage(3.3, false)

setVoltage() takes a code from 0 to 4095, not volts, so 3.3 becomes 3. For a voltage V on supply Vs, send V / Vs x 4095, rounded.

### Updates stop working for a moment after storing a value

Writing the EEPROM keeps the chip busy for about 25 ms, during which it ignores writes, as the real one does. Wait before the next setVoltage(), and store to EEPROM only when the startup value must change.

## Questions and answers

### Why does the MCP4725 example read A0?

VOUT is wired to A0, so analogRead() shows each code arriving: 1024 out of 4096 should read about 256 out of 1024 on the Uno’s converter.

### Can the MCP4725 play a waveform?

Yes, by calling setVoltage() from a table in a loop, but each step is a whole I2C transfer, so the rate is limited by the bus clock rather than the chip.

## Projects that use Adafruit MCP4725

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

DAC sine wave An MCP4725 on I2C plays a 32-point sine onto a scope: a real voltage, not PWM, and A0 reads it back to check.

## Keep going

### Learn

- PWM to an Analog Voltage With an RC Filter
- I2C Scanner for Arduino and ESP32, and Fixes

### Parts

- DAC, MCP4725

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280
- SparkFun MLX90614
- MD_TCS230
- SparkFun BME280
- MCP4725
- DHT sensor library for ESPx
- SparkFun BMP180 (SFE_BMP180)

Every built-in library · Open the editor

## Try Adafruit MCP4725 without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
