Example Code for Arduino-Output 10V in 0–10V Range (I2C Mode)

Last revision 2026/02/11

Control the module to output 10V within the 0–10V range via I2C communication on the ESP32-E main controller, and verify the result with a multimeter.

Hardware Preparation

Software Preparation

Wiring Diagram

DFR1230-I2C WIRING

Connect the module to the ESP32-E as shown in the diagram. The core corresponding relationships are as follows:

  • Module I2C interface "+" → ESP32-E 3.3V
  • Module I2C interface "-" → ESP32-E GND
  • Module I2C interface "SCL" → ESP32-E SCL (default GPIO22)
  • Module I2C interface "SDA" → ESP32-E SDA (default GPIO21)

Other Preparation Work

  • DIP switch configuration: A0=0, A1=0, A2=0 (I2C address = 0x58)

Sample Code

Open Arduino IDE, copy the following code, and upload it to the ESP32-E:

#include <DFRobot_GP8XXX.h>

// Enable I2C communication mode
#define I2C_COMMUNICATION
// Set the module I2C address to 0x58
#define MODULE_I2C_ADDRESS 0x58

// Create an I2C communication object
DFRobot_GP8630N_I2C GP8630N(&Wire, MODULE_I2C_ADDRESS);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  
  // Initialize the DAC module
  while (GP8630N.begin() != 0) {
    Serial.println("Communication with the device failed. Please check if the connection is normal or if the device address is set correctly.");
    delay(1000);
  }
  Serial.println("Successful connection!");
  
  // Set the output range to 0–10V
  GP8630N.setDACOutRange(GP8630N.eOutputRange10V);
  
  // Output 10V (65535 corresponds to the full-scale 10V output)
  GP8630N.setDACOutData(65535);
}

void loop() {
  // No loop operations required; the output is maintained with a single configuration
}

Result

  1. Set the multimeter to the "DC V" range;
  2. Connect the red probe to the module's "OUT" terminal and the black probe to the module's "GND" terminal;
  3. Under normal conditions, the measured voltage should be close to 10V. In this example, the actual measured output voltage is 10.04V.

DFR1230-i2c result

Was this article helpful?

TOP