I2C 4-20mA DAC Module Arduino Wiki - DFRobot

Introduction

This is an I2C DAC module that outputs 0-25mA current. It offers more accurate 4-20mA current output after calibration, which can be used with most 4-20mA devices on markets such as motors, inverters, valves, pumps, etc., by Arduino programming.

Features

Applications

Specification

Dimension Diagram

Function Indication

Tutorial

Requirements

Hardware Connection

Step 1: Insert the probe of the multimeter into the jack for current, and change it to DC current, as shown in the figure:

Step 2: Adjust the voltage of the experimental power supply to 24V, as shown in the figure:

Step 3: Connect the UNO main board, the experimental power supply, the current module, the load resistor and the multimeter according to the figure:

The test proved that the result is incorrect when using load meter as load resistor, because the load meter is not a pure resistance load, which will lead to inaccurate output voltage.

Programming

Write and download the following code into the UNO main board to make the current module output a current of 10mA, and save the value in the module. Changing the value in the "module.output(10)" function can change the output current, the range of the value is 0-25, corresponding to 0-25mA respectively.


#include "DFRobot_GP8302.h"

DFRobot_GP8302 module;

void setup(){
  Serial.begin(115200);

  while(!Serial){

  }
  Serial.print("I2C to 0-25 mA analog current moudle initialization ... ");
  uint8_t status = module.begin(); // use the pin used by the I2C Wire object of the MCU hardware by default

  if(status != 0){
    Serial.print("failed. Error code: ");
    Serial.println(status);
    Serial.println("Error Code: ");
    Serial.println("\t1: _scl or _sda pin is invaild.");
    Serial.println("\t2: Device not found, please check if the device is connected.");
    while(1) yield();
  }
  Serial.println("done!");

  uint16_t dac = module.output(10); //control the converter module to output a current of 10mA and return the corresponding DAC value
  Serial.print("DAC value: 0x"); Serial.println(dac, HEX);
  module.store(); Serial.println("Save current configuration."); //the above current config will be saved and will not be lost after power off
}

void loop(){

}

Result

As shown in the figure, the multimeter shows an output current of 10.05mA. The error is 0.05mA (0.5%), which is resulted from the accuracy of the multimeter and lack of calibration.

Calibrate to Obtain Accurate Current Within 4-20mA

The module supports outputting current within 0-25mA. And through a two-point calibration of 4mA and 20mA, an accurate current within 4-20mA can be obtained. The Arduino library provides the functions for easy current calibration.

For calibration, first input the exact DAC value for 4mA and for 20mA respectively, then output the current of 4mA and check the actual output value on the ammeter, finally adjust the DAC value until the actual output is exactly 4mA; similarly, output the current of 20mA and check the actual output value on the ammeter, finally adjust the DAC value until the actual output is exactly 20mA. Then the values in 4-20mA are calibrated.

Calibration Steps:

     #include "DFRobot_GP8302.h"

      DFRobot_GP8302 module;

      void setup(){
        Serial.begin(115200);

        while(!Serial){
          //Wait for USB serial port to connect. Needed for native USB port only
        }

        Serial.print("I2C to 0-25 mA analog current moudle initialization ... ");

        uint8_t status = module.begin(); // use the pin used by the I2C Wire object of the MCU hardware by default

        if(status != 0){
          Serial.print("failed. Error code: ");
          Serial.println(status);
          Serial.println("Error Code: ");
          Serial.println("\t1: _scl or _sda pin is invaild.");
          Serial.println("\t2: Device not found, please check if the device is connected.");
          while(1) yield();
        }
        Serial.println("done!");

        module.calibration4_20mA(/*dac_4 =*/652, /*dac_20 =*/3265);

        uint16_t dac = module.output(/*current_mA =*/4); 
      }

      void loop(){

      }

Calibrate 4mA:

Calibrate 20mA:

So the calibration of the current within 4-20mA is complete. The calibrated current value within 4-20mA can be output using this statement: uint16_t dac = module.output(/*current_mA =*/10);

Function Library Definition

Function prototype: uint8_t begin(int scl = -1, int sda = -1)
Function brief: initialize the current module, and configure the I2C pin.
Parameter: scl IO port pin of the MCU, sda IO port pin of the MCU; when scl and sda use the default formal parameter, they are the pins corresponding to MCU hardware I2C
Return value: 0 init success; 1 the I2C pin of the MCU connected to the I2C to current DAC module is invalid; 2 device not found, please check if the connection is correct

Function prototype: float output_mA(uint16_t dac)
Function brief: set DAC value to control the device to output the current, the range is 0~0xFFF, corresponding to outputting 0~25mA, the formula for DAC value converting to actual current: Iout=(DAC/0xFFF)*25mA 
Parameter: DAC value of 0~0xFFF
Return value: actual current, unit mA

Function prototype: uint16_t output(float current_mA)
Function brief: set current value to control the device to output the current, the range is 0-25, corresponding to outputting 0~25mA.
Parameter: current value of 0-25
Return value: the hexadecimal DAC value corresponding to the output current value, range is 0~0~0xFFF

Function prototype: void store()
Function brief: save the current config, after the config is saved successfully, it will be enabled when the module is powered off and restarts.
Parameter: none
Return value: none

Function Prototype: module.calibration4_20mA(dac_4, dac_20)
Function brief: calibrate the current within 4~20mA
Parameter:
dac_4   range 0~4095, the calibration is invalid if the value is out of the range, the DAC value corresponding to the current of 4mA
dac_20   range 0~4095, the calibration is invalid if the value is out of the range, the DAC value corresponding to the current of 20mA
dac_4 and dac_20 should meet the condition: dac_4 < dac_20
Return value: none

More Documents

DFR0972_Schematics.pdf

DFR0972_Dimensions.pdf

DFR0972_2D_CAD File.rar

DFR0972_3D Model File.rar

GP8302 Datasheet.pdf

FAQ

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