MCP Bit DAC Tutorial

Similar documents
MCP Bit DAC Tutorial

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Adafruit I2C FRAM Breakout

Monochrome OLED Breakouts

Adafruit DRV2605 Haptic Controller Breakout

i2c/spi LCD Backpack Created by lady ada Last updated on :11:04 PM UTC

Adafruit Si7021 Temperature + Humidity Sensor

Adafruit Si5351 Clock Generator Breakout

Adafruit MMA8451 Accelerometer Breakout

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

Adafruit APDS9960 breakout

Adafruit MMA8451 Accelerometer Breakout

Adafruit Capacitive Touch Sensor Breakouts

Adafruit MPRLS Ported Pressure Sensor Breakout

Introducing Adafruit Trellis

Adafruit AM2320 Sensor

Adafruit DRV2605 Haptic Controller Breakout

Adafruit CCS811 Air Quality Sensor

TSL2561 Luminosity Sensor

Adafruit 8x16 LED Matrix FeatherWing

Joy Featherwing. Created by Dean Miller. Last updated on :03:07 PM UTC

Adafruit Mini TFT " 160x80

1.8" TFT Display Breakout and Shield

Adafruit MMA8451 Accelerometer Breakout

Adafruit 1.27" and 1.5" Color OLED Breakout Board

Adafruit SGP30 TVOC/eCO2 Gas Sensor

Adafruit PowerBoost 500 Shield

Adafruit Color Sensors

IS31FL x9 Charlieplexed PWM LED Driver

Adafruit LIS3DH Triple-Axis Accelerometer Breakout

0.96" mini Color OLED

RGB LCD Shield. Created by lady ada. Last updated on :48:40 PM UTC

Adafruit AS channel Visible Light Sensor

Adafruit DS3231 Precision RTC Breakout

Adafruit AMG8833 8x8 Thermal Camera Sensor

Adafruit 7-Segment LED FeatherWings

Adafruit GPIO Expander Bonnet for Raspberry Pi Created by Kattni Rembor. Last updated on :12:47 PM UTC

Adafruit TPL5111 Reset Enable Timer Breakout

Adafruit 8x16 LED Matrix FeatherWing

Adafruit PCF8523 Real Time Clock

Adafruit TPL5110 Power Timer Breakout

Adafruit ATWINC1500 WiFi Breakout

Adafruit HUZZAH32 - ESP32 Feather

Adafruit 9-DOF IMU Breakout

Adafruit LED Backpacks

Adafruit MAX31865 RTD PT100 or PT1000 Amplifier

14-Segment Alpha-numeric LED FeatherWing

MLX90393 Wide-Range 3-Axis Magnetometer

FeatherWing Proto and Doubler

FeatherWing Proto, Doubler and Tripler

Adafruit ATWINC1500 WiFi Breakout

Adafruit Mini TFT with Joystick Featherwing

Adafruit LED Backpacks

Adafruit Pi Cobbler Kit

Adafruit 10-DOF IMU Breakout

Introducing Circuit Playground

Introducing Circuit Playground

Adafruit ATWINC1500 WiFi Breakout

Neon LED Signs. Created by John Park. Last updated on :11:09 PM UTC

Adafruit WINC1500 WiFi Shield for Arduino

Adafruit 2.4" TFT FeatherWing

Flora Wearable GPS. Created by Becky Stern. Last updated on :32:36 PM UTC

Adafruit Feather 32u4 Basic Proto

Adafruit 3.5" 480x320 TFT FeatherWing

NeoMatrix 8x8 Word Clock

Adafruit 3.5" 480x320 TFT FeatherWing

MiniPOV4 - DIY Full-Color Persistence of Vision & Light-Painting Kit

Adafruit TSL2591 High Dynamic Range Digital Light Sensor

Trellis 3D Printed Enclosure

Adafruit eink Display Breakouts

NeoPixel Ring Bangle Bracelet

Adafruit IO Basics: Servo

Using IFTTT with Adafruit IO to Make an IoT Door Detector

Adafruit LED Sequins. Created by Becky Stern. Last updated on :02:00 AM UTC

FLORA TV-B-Gone. Created by Becky Stern. Last updated on :32:57 PM UTC

DC & USB Boarduino Kits

Naughty or Nice Machine

Data Logging with Feather and CircuitPython

Sino:bit with Arduino

Sewable NeoPixels. Created by Becky Stern. Last updated on :50:14 PM EDT

Jewel Hair Stick. Created by Leslie Birch. Last updated on :47:17 PM UTC

Bike Wheel POV Display

Adafruit Flora Bluefruit LE

Prophet 600 GliGli mod

Toy Car Speed Timer. Created by Kirby Griese. Last updated on :13:49 PM UTC

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :42:16 PM UTC

Adafruit Prototyping Pi Plate. Created by Ladyada

Phone-Activated Talking Dog Collar

Adafruit Stepper + DC Motor FeatherWing

Trinket-Powered Conference Room Occupancy Display

Coffee Detonator: The TNT Plunger Grinder

Interior Purse Light. Created by Becky Stern. Last updated on :41:08 PM UTC

LED Eyes. Created by Ruiz Brothers. Last updated on :50:55 AM UTC

PyPortal NeoPixel Color Picker Created by Kattni Rembor. Last updated on :42:41 PM UTC

Light-Up Angler Fish Embroidery

Lady Ada's Bento Box. Created by lady ada. Last updated on :55:35 AM UTC

Arduino Lesson 6. Digital Inputs

Getting Started with FLORA

Circuit Playground Digital Input

Circuit Playground Express Laser Tag

Transcription:

MCP4725 12-Bit DAC Tutorial Created by lady ada Last updated on 2016-10-07 04:47:03 PM UTC

Guide Contents Guide Contents Overview Wiring Using with Arduino Using the library Increasing the speed Download Files Schematic & Fabrication Print 2 3 5 8 9 9 11 11 11 Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 2 of 12

Overview 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-touse 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 Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 3 of 12

output range is 0-3.3V. If you run it from 5V the output range is 0-5V. Available from the Adafruit shop! (http://adafru.it/935) Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 4 of 12

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 Place the breakout board on top so the short ends of the header stick up through the pads Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 5 of 12

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 Now that the header is attached, we can wire it up. We'll demonstrate using an Arduino. FIrst, connect VDD (power) to a 3-5V power supply, and GND to ground. The DAC uses I2C, a two-pin interface that can have up to 127 unique sensors attached (each must have a different ADDRESS). SDA to I2C Data (on the Uno, this is A4 on the Mega it is 20 and on the Leonardo digital 2) SCL to I2C Clock(on the Uno, this is A5 on the Mega it is 21 and on the Leonardo digital 3) There's two other pins remaining. Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 6 of 12

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) Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 7 of 12

Using with Arduino Next up, download the Adafruit MCP4725 library. This library does all of the interfacing, so you can just "set and forget" the DAC output. It also has some examples to get you started The library is available on GitHub (http://adafru.it/apz). You can download it by clicking the button below. Download Adafruit_MCP4725 Library http://adafru.it/cda Rename the uncompressed folder Adafruit_MCP4725. Check that the Adafruit_MCP4725 folder contains Adafruit_MCP4725.cpp and Adafruit_MCP4725.h Place the Adafruit_MCP4725 library folder your sketchbookfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. You can figure out your sketchbookfolder by opening up the Preferences tab in the Arduino IDE. Restart the IDE. 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) Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 8 of 12

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 Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 9 of 12

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. Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 10 of 12

Download Files For more details about the chip, please check out the MCP4725 datasheet (http://adafru.it/arw) MCP4725 Arduino Library is on GitHub (http://adafru.it/apz) Fritzing object in the Adafruit Fritzing library (http://adafru.it/ap3) EagleCAD PCB files on GitHub (http://adafru.it/rmc) Schematic & Fabrication Print Adafruit Industries https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial Page 11 of 12

Adafruit Industries Last Updated: 2016-10-07 04:47:02 PM UTC Page 12 of 12