Example Code for Arduino-Generate Voltage
In this example,We will demonstrate the generation of distinct voltage values under two different conditions. Input signal value range: 0 - 32767 - In the state of 0-2.5V: input 24903, resulting in an output of 1.9V. - In the state of 0-VCC: input 24903, resulting in an output of 3.8V.
Hardware Preparation
| Name | Model/SKU | Quantity | Purchase Link |
|---|---|---|---|
| DFR1035 GP8512 1-Channel 15bit I2C to 0-2.5V/VCC DAC Module | DFR1035 | 1 | Product Link |
| DFRobot arduino uno r3 | DFR0216 | 1 | Product Link |
Software Preparation
-
Download Arduino IDE: Click to download Arduino IDE
-
Download Arduino libraries: Click to download https://github.com/DFRobot/DFRobot_GP8XXX
Click the link to view:How to install the library?;
Wiring Diagram

Sample Code
#include <DFRobot_GP8XXX.h>
DFRobot_GP8512 GP8512;
void setup() {
Serial.begin(9600);
while(GP8512.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);
}
/**
* @brief. Set the output DAC value.
* @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-2.5V or 0-VCC respectively. The specific voltage range depends on the selection of the module's voltage fluctuation switch.
*/
GP8512.setDACOutVoltage(24903);//Output voltage of 1.9V under the 0-2.5V state and 3.8V under the 0-VCC state.
delay(1000);
//The set voltage is saved internally in the chip for power-off retention.
//GP8512.store();
}
void loop() {
}
Result
After downloading the program, the voltmeter was used to measure the actual output voltage of 1.9V under the 0-2.5V state and 3.8V under the 0-VCC state.
Was this article helpful?
