Example Code for Arduino-Sine Wave Output

Last revision 2025/12/27

This guide explains how to generate a 10Hz sine wave using Arduino and ESP32 with the GP8403 DAC module, including hardware setup, wiring, and code implementation.

Hardware Preparation

Software Preparation

Wiring Diagram

DFR0971-Wiring diagram

Wring Description

FireBeetle 2: 3V3 to DAC module: +

FireBeetle 2: GND to DAC module: -

FireBeetle 2: SCL to DAC module: SCL

FireBeetle 2: SDA to DAC module: SDA

Sample Code

Initialize GP8403 DAC, output 10Hz sine wave on OUT0.

#include "DFRobot_GP8403.h"
DFRobot_GP8403 dac(&Wire,0x58);

void setup() {
  Serial.begin(115200);
  while(dac.begin()!=0){
    Serial.println("init error");
    delay(1000);
   }
  Serial.println("init succeed");
  //Set DAC output range
  dac.setDACOutRange(dac.eOutputRange5V);
}

void loop(){
 dac.outputSin(2500, 10, 2500, 0);//(voltage value, frequency (0~100Hz), voltage value, channel number)
}

Result

After downloading the code, a sine waveform with a frequency of 9.804Hz and an amplitude of ±2.5V can be observed on the oscilloscope display.

DFR0971-Result

Was this article helpful?

TOP