Tutorial: MCP4725 12-Bit DAC with Raspberry Pi @ The Adafruit Learning System –
Already mastered Analog Inputs with the Pi, and looking for a new challenge? How about: How can I generate an analog output on the Pi?!
There are several ways you can accomplish this, but one of the easiest and most flexible is to use a dedicated IC called a Digital to Analog Convertor (or DAC). A DAC allows you to specify a numeric value (0..255 for an 8-bit DAC, 0..4095 for a 12-bit DAC, etc.), and the IC will output a voltage based on the supply voltage, and relative to that numeric value. For example, using a 12-bit DAC like the MCP4725 we’ll be using here, setting the value to 2048 on a 3.3V system will results in ~1.65V output on the DAC.
This guide will show you everything you need to know to be able to generate precise analog outputs using your Pi and the MCP4725 12-Bit I2C DAC, from connecting everything up, to how to use our easy Python library.
MCP4725 Breakout Board – 12-Bit DAC w/I2C Interface. 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 pin so you can connect two of these DACs on one I2C bus, just tie the ADDR pin of one high 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.
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 library with a triangle-wave output example that can be used with any ‘duino or ported to any microcontroller with I2C host. Wiring it up is easy – connect VDD to your microcontroller power pin (3-5V), GND to ground, SDA to I2C Data (on the Arduino Uno, this is A4 on the Mega it is 20 and on the Leonardo digital 2), SCL to I2C Clock(on the Arduino Uno, this is A5 on the Mega it is 21 and on the Leonardo digital 3) and listen on VOUT.
For more information about the chip, check out the MCP4725 datasheet
Each Friday is PiDay here at Adafruit, be sure to check out our posts, tutorials and new Raspberry Pi related products. Have you tried the new “Adafruit Raspberry Pi Educational Linux Distro” ? It’s our tweaked distribution for teaching electronics using the Raspberry Pi.
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!
Maker Business — “Inside One of the World’s Most Secretive iPhone Factories”
Wearables — It’s not cheating
Electronics — Blown transistor?
Biohacking — “1 Minute of All-Out Exercise May Have Benefits of 45 Minutes of Moderate Exertion”
No comments yet.
Sorry, the comment form is closed at this time.