Using the DACx578 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_DACX578 library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the DAC VIN.
Here is an Adafruit Metro wired up to the DAC using the STEMMA QT connector:
-
Board 5V to DAC VCC (red wire)
-
Board GND to DAC GND (black wire)
-
Board SCL to DAC SCL (yellow wire)
- Board SDA to DAC SDA (blue wire)
You can output a signal from any of the 8 DAC channels.
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to DAC VCC (red wire)
-
Board GND to DAC GND (black wire)
-
Board SCL to DAC SCL (yellow wire)
- Board SDA to DAC SDA (blue wire)
You can output a signal from any of the 8 DAC channels.
Library Installation
You can install the Adafruit_DACX578 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_DAC7578, and select the Adafruit DAC7578 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!
#include <Adafruit_DACX578.h> #include <math.h> Adafruit_DACX578 dac(12); // Assuming 12-bit resolution const float frequencies[8] = {1, 2, 4, 8, 16, 32, 40, 50}; // Hz const uint16_t amplitude = 2048; // Half of full scale for 12-bit DAC (0 to 4095) const uint16_t offset = 2048; // DC offset to keep sine wave positive const uint32_t sampleRate = 370; // Measured actual rate const uint32_t period = 2700; // Measured cycle time in microseconds void setup() { Serial.begin(115200); while (!Serial) delay(10); Serial.println("Adafruit DACX578 Sine Wave Test"); if (!dac.begin()) { Serial.println("Failed to find DAC7578 chip"); while (1) delay(10); } Serial.println("DAC7578 initialized"); // Set I2C frequency to 800 kHz for faster communication Wire.setClock(800000); } void loop() { static uint32_t lastTime = micros(); static float phase[8] = {0}; uint32_t currentTime = micros(); if (currentTime - lastTime >= period) { lastTime = currentTime; // Use actual time for (uint8_t channel = 0; channel < 8; channel++) { float sineValue = sin(phase[channel]) * amplitude + offset; dac.writeAndUpdateChannelValue(channel, (uint16_t)sineValue); // Update phase using actual sample rate phase[channel] += 2 * M_PI * frequencies[channel] / sampleRate; if (phase[channel] >= 2 * M_PI) { phase[channel] -= 2 * M_PI; } } } }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the DACx578 recognized over I2C. Then, sinewaves will be output to each of the 8 channels on the DAC. You can connect these outputs to your oscilloscope to measure the frequency. In the image above, channels 0 (1 Hz) and 2 (4 Hz) on the DAC are connected to the two input channels on the oscilloscope.
Page last edited March 06, 2025
Text editor powered by tinymce.