Example Code for Arduino-Dual-channel Voltage Output
This program is used to control the PWM-driven 2-channel DAC module to output the specified analog voltage.
Hardware Preparation
| Name | Model/SKU | Quantity | Purchase Link |
|---|---|---|---|
| DFR1037 Gravity: GP8501 2 - Channel PWM to 0 - 2.5V/VCC DAC Module | DFR1037 | 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>
//#define SINGLE_CHANNEL
#ifdef SINGLE_CHANNEL
//Single-channel output IO port
int pwmPin0 = 9;
DFRobot_GP8501 GP8501(pwmPin0);
#else
//Dual-channel output IO port
int pwmPin0 = 9;
int pwmPin1 = 10;
DFRobot_GP8501 GP8501(pwmPin0,pwmPin1);
#endif
void setup() {
GP8501.begin();
/**
* @brief. Configuring different channel outputs for DAC values
* @param data pwm
* @n. Optional parameters (0-255) correspond to voltage ranges of (0-2.5V) or (0-VCC), and the specific voltage range is determined by the fluctuation switch selected based on the module voltage.
* @param channel. Output channel
* @n 0:Channel 0 (effective when configuring PWM0 output.)
* @n 1:Channel 1 (effective when configuring PWM1 output.)
* @n 2:All Channels (effective when configuring Dual-channel output.)
*/
GP8501.setDACOutVoltage(176,0);//At 0-2.5V voltage range, Channel 0 outputs 1.725V, whereas at 0-VCC voltage range, Channel 0 outputs 3.29V.
GP8501.setDACOutVoltage(103,1);//At 0-2.5V voltage range, Channel 1 outputs 1.009V, whereas at 0-VCC voltage range, Channel 1 outputs 1.926V.
}
void loop() {
}
Result
After downloading the program, the measured output voltage of channel 0 under the 0-2.5V state is 1.725V, and the output voltage of channel 1 is 1.009V. Under the 0-VCC state, the actual output voltage of channel 0 is 3.29V, and the output voltage of channel 1 is 1.926V.
Was this article helpful?
