Example Code for Arduino-Voltage Output
Last revision 2025/12/03
This article offers example code for Arduino to demonstrate voltage output in two states, showing how specific input values affect the resulting voltage.
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?;
Note: All modules in this series utilize the same library.
Wiring Diagram
Sample Code
#include <DFRobot_GP8XXX.h>
DFRobot_GP8503 GP8503;
void setup() {
Serial.begin(9600);
while(GP8503.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. Configuring different channel outputs for DAC values
* @param data. Data values corresponding to voltage values
* @n (0 - 4095).This module is a 12-bit precision DAC module, hence the values ranging from 0 to 4095 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.
* @param channel Output Channel
* @n 0:Channel 0
* @n 1:Channel 1
* @n 2:AII channels
*/
GP8503.setDACOutVoltage(2654,0);//At 0-2.5V voltage range, Channel 0 outputs 1.62V, whereas at 0-VCC voltage range, Channel 0 outputs 3.23V.
GP8503.setDACOutVoltage(1095,1);//At 0-2.5V voltage range, Channel 1 outputs 0.668V, whereas at 0-VCC voltage range, Channel 1 outputs 1.334V.
delay(1000);
//The set voltage is saved internally in the chip for power-off retention.
//GP8503.store();
}
void loop() {
}
Result
After downloading the program, the measured output voltage of channel 0 under the 0-2.5V state is 1.62V, and the output voltage of channel 1 is 0.668V. Under the 0-VCC state, the actual output voltage of channel 0 is 3.23V, and the output voltage of channel 1 is 1.334V.
Was this article helpful?

