Example Code for Arduino-Voltage Output Correlation

This program demonstrates connecting a DAC module via the I2C interface of Arduino UNO R3 to output analog voltage.

Hardware Preparation

Name Model/SKU Quantity Purchase Link
DFR1071 GP8211S 1-Channel 15-bit I2C to 0-5V/10V DAC Module DFR1071 1 Product Link
DFRobot arduino uno R3 DFR0216 1 Product Link

Software Preparation

Wiring Diagram

Sample Code

#include <DFRobot_GP8XXX.h>

DFRobot_GP8211S GP8211S;

void setup() {

  Serial.begin(9600);

  while(GP8211S.begin()!=0){
    Serial.println("Communication with the device has encountered a failure. Please verify the integrity of the connection or ensure that the device address is properly configured.");
    delay(1000);
  }
GP8211S.setDACOutRange(GP8211S.eOutputRange10V);
  /**
   * @brief. Configuring different channel outputs for DAC values
   * @param data. Data values corresponding to voltage values
   * @n (0 - 32767).This module is a 15-bit precision DAC module, hence the values ranging from 0 to 32767 correspond to voltages of 0-10V respectively.
   */
  GP8211S.setDACOutVoltage(21456);//Output 6.548V

  delay(1000);

  //The set voltage is saved internally in the chip for power-off retention.
  //GP8211S.store();
}

void loop() {

}

Result

After downloading the program, the actual output voltage of channel was measured as 6.548V using a voltmeter.

Was this article helpful?

TOP