Gravity__12-Bit_I2C_DAC_Module_SKU__DFR0552-DFRobot

Introduction

DFRobot Gravity 12-Bit I2C DAC is a small and easy-to-use 12-bit digital-to-analog converter with EEPROM. It can accurately convert the digital value to corresponding analog voltage signal, which is useful in may creative projects and automatic control systems. Although an analog voltage signal can be generated by PWM with traditional controllers such as Arduino and Raspberry Pi, such signal is ROUGH and NOT ACCURATE. To obtain a steady and nice analog voltage signal, the DAC is the best candidate. In addition to be applied in automatic control systems, the DAC module can be use to serve as a function generator to generate sine wave, triangular wave and even arbitrary waveform (we provide a library to generate low frequency sin and triangular wave with just a few parameters).

The module employs a 12-bit DAC MCP4725. It requires no external reference voltage (DAC reference is driven from VCC directly), supports 3.3V~5V wide input voltage and has a I2C address selection switch (two address 0x60 and 0x61 are available, which support maximum two modules in cascade). The EEPROM can retain the DAC input while power-off and resume the DAC output upon power-on.

Features

Applications

Specifications

Board Overview


Label Name Description
+ VCC Power VCC(3.3~5.0V)
- GND Power GND
C SCL I2C Clock Signal
D SDA I2C Data Signal
ADDR I2C address I2C address selection switch(0x60 or 0x61)
VOUT VOUT DAC analog voltage output(0~VCC)

Arduino Tutorial

Requirements

Connection Diagram


Calibration and adjustable analog voltage output

Although the DAC's voltage output accuracy is affected by several factors that cause the actual output voltage to deviate from the user-specified voltage values, the DAC reference voltage, Vref, of the MCP4725 is the same as the supply voltage VCC, and the supply voltage is usually not accurate (the actual voltage is not exactly 5.000 V or 3.300V), which results in large output error. Here, we provide a simple calibration method to eliminate the error caused by the inaccurate reference voltage. If calibration is not carried out, users can still simply set REF_VOLTAGE to 5000 in the code below (for a 5V controller such as an Arduino) or 3300 (for a 3.3V controller such as Raspberry Pi, FireBeetle) depending on the controller used.

Users are required an additional high-precision digital multimeter to complete the calibration, the specific steps are as follows:

  1. Connect the module to the Arduino according to the connection diagram above and set I2C address to 0x60 by ADDR switch on the module. If I2C address 0x61 is preferred, you need to modify the first parameter of the function DAC.init() in the code below.
  2. Install the MCP4725 library
  3. Open Arduino IDE and upload the following code to Arduino UNO
  4. Use the multimeter to measure the output voltage of VOUT and change the value of REF_VOLTAGE accordingly. For example, VOUT = 4950mV, the "#define REF_VOLTAGE 5000" should be revised to "#define REF_VOLTAGE 4950". Calibration completed.
/*
 * file OutputVoltage.ino
 *
 * @ https://github.com/DFRobot/DFRobot_MCP4725
 *
 * connect MCP4725 I2C interface with your board (please reference board compatibility)
 *
 * Output a constant voltage value and print through the serial port.
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-1-15
 */
#include "DFRobot_MCP4725.h"
#define  REF_VOLTAGE    5000

DFRobot_MCP4725 DAC;

uint16_t OUTPUT_VOLTAGE = 5000;        // Input DAC output voltage (0~REF_VOLTAGE,unit: mV)

void setup(void) {

  Serial.begin(115200);
  /* MCP4725A0_address is 0x60 or 0x61
   * MCP4725A0_IIC_Address0 -->0x60
   * MCP4725A0_IIC_Address1 -->0x61
   */
  DAC.init(MCP4725A0_IIC_Address0, REF_VOLTAGE);

}

void loop(void) {

  Serial.print("DFRobot_MCP4725 output: ");
  Serial.print(OUTPUT_VOLTAGE);
  Serial.println(" mV");

  DAC.outputVoltage(OUTPUT_VOLTAGE);

  delay(500);
}

Store the DAC Value in EEPROM

/*
 * file OutputVoltageEEPROM.ino
 *
 * @ https://github.com/DFRobot/DFRobot_MCP4725
 *
 * connect MCP4725 I2C interface with your board (please reference board compatibility)
 *
 * Output a constant voltage value and write to the internal EEPROM.
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-1-15
 */
#include "DFRobot_MCP4725.h"
#define  REF_VOLTAGE    5000

DFRobot_MCP4725 DAC;

uint16_t OUTPUT_VOLTAGE = 1000;        // Input DAC output voltage (0~REF_VOLTAGE,unit: mV)

void setup(void) {

  Serial.begin(115200);
  /* MCP4725A0_address is 0x60 or 0x61
   * MCP4725A0_IIC_Address0 -->0x60
   * MCP4725A0_IIC_Address1 -->0x61
   */
  DAC.init(MCP4725A0_IIC_Address0, REF_VOLTAGE);

}

void loop(void) {

  Serial.print("DFRobot_MCP4725 write to EEPROM and output: ");
  Serial.print(OUTPUT_VOLTAGE);
  Serial.println(" mV");

  DAC.outputVoltageEEPROM(OUTPUT_VOLTAGE);

  delay(200);
}

Results

Output a Sine Wave

/*
 * file OutputVoltage.ino
 *
 * @ https://github.com/DFRobot/DFRobot_MCP4725
 *
 * connect MCP4725 I2C interface with your board (please reference board compatibility)
 *
 * Output a constant voltage value and print through the serial port.
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-1-25
 */
#include "DFRobot_MCP4725.h"
#define  REF_VOLTAGE    5000

DFRobot_MCP4725 DAC;

void setup(void) {
  Serial.begin(115200);
  /* MCP4725A0_address is 0x60 or 0x61
   * MCP4725A0_IIC_Address0 -->0x60
   * MCP4725A0_IIC_Address1 -->0x61
   */
  DAC.init(MCP4725A0_IIC_Address0, REF_VOLTAGE);
}

void loop(void) {
  /*Output a magnitude of 2500mv, the frequency of 10HZ, DC offset 2500mv sine wave*/
  DAC.outputSin(2500,10,2500);
}

Results


void outputSin(uint16_t amp, uint16_t freq, uint16_t offset)

Output a Triangle Wave

/*
 * file OutputVoltage.ino
 *
 * @ https://github.com/DFRobot/DFRobot_MCP4725
 *
 * connect MCP4725 I2C interface with your board (please reference board compatibility)
 *
 * Output a constant voltage value and print through the serial port.
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-1-25
 */
#include "DFRobot_MCP4725.h"
#define  REF_VOLTAGE    5000

DFRobot_MCP4725 DAC;

void setup(void) {
  Serial.begin(115200);
  /* MCP4725A0_address is 0x60 or 0x61
   * MCP4725A0_IIC_Address0 -->0x60
   * MCP4725A0_IIC_Address1 -->0x61
   */
  DAC.init(MCP4725A0_IIC_Address0, REF_VOLTAGE);
}

void loop(void) {
  /*Output amplitude 5000mv, frequency 10HZ,
   *the rise of the entire cycle accounted for 50% of the DC offset 0mv triangular wave.
   */
  DAC.outputTriangle(5000,10,0,50);
}

Results


void outputTriangle(uint16_t amp, uint16_t freq, uint16_t offset, uint8_t dutyCycle)


Raspberry Pi Tutorial

Requirements

Connection Diagram


Installation

1.Start the I2C interface of the Raspberry Pi. If it is already open, skip this step. Open Terminal, type the following command, and press Enter:

 pi@raspberrypi:~ $ sudo raspi-config

Then use the up and down keys to select “5 Interfacing Options” -> “P5 I2C” and press Enter to confirm “YES”. Reboot the Raspberry Pi.

2.Installing Python libraries and git (networking required). If it is already installed, skip this step. In the Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

3.Download the driver library and run it.In the Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ git clone https://github.com/DFRobot/DFRobot_MCP4725.git
pi@raspberrypi:~ $ cd /home/pi/DFRobot_MCP4725/RaspberryPi/python
pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python $ sudo python DFRobot_MCP4725.py

Calibration and Adjustable Analog Voltage Output

Users are required an additional high-precision digital multimeter to complete the calibration, the specific steps are as follows:

 pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python $ cd OutputVoltage
 pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python/OutputVoltage $ sudo python OutputVoltage.py

1.Use the IDLE integrated development environment to modify Python programs in a graphical environment. Click "File Manager" in the menu bar, and then type the following address in the address bar

/home/pi/DFRobot_MCP4725/RaspberryPi/Python/OutputVoltage

Right click on the Python source code "OutputVoltage.py" in the directory. Select “Python 3 (IDLE)” from the menu and edit the Python program in the pop-up window. After editing, use the shortcut “Ctrl S” to save and closed window.



2.Use the nano editor to modify Python programs in the Terminal. In the Terminal, enter the following commands:

pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python/OutputVoltage $ nano OutputVoltage.py

After entering the commands, a Python program is opened using the nano editor. After completing the code modification, use the shortcut “Ctrl O” to save, press Enter to confirm, and then use the shortcut “Ctrl X” to close the nano editor.


Store the DAC Value in EEPROM

pi@raspberrypi:~ $ cd ~/DFRobot_MCP4725/RaspberryPi/Python/OutputVoltageEEPROM
pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python/OutputVoltageEEPROM $ sudo python OutputVoltageEEPROM.py

Results

Generate a Sine Wave

pi@raspberrypi:~ $ cd ~/DFRobot_MCP4725/RaspberryPi/Python/OutputSin
pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python/OutputSin $ sudo python OutputSin.py

Results


 outputSin(amp,freq,offset)

Generate a Triangle Wave

pi@raspberrypi:~ $ cd ~/DFRobot_MCP4725/RaspberryPi/Python/OutputTriangle
pi@raspberrypi:~/DFRobot_MCP4725/RaspbeeryPi/python/OutputTriangle $ sudo python OutputTriangle.py

Results


 outputTriangle(amp,freq,offset,dutyCycle)


FAQ

For more questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Gravity: I2C 12-Bit DAC Module from DFRobot Store or DFRobot Distributor.

Turn to the Top