It's easy to use the DACx578 with Python or CircuitPython, and the Adafruit_CircuitPython_x578 module. This module allows you to easily write Python code to write data to the DAC outputs.
You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
CircuitPython Microcontroller Wiring
First wire up the DAC to your board exactly as follows. The following is the DAC wired to a Feather RP2040 using the STEMMA connector:
-
Board STEMMA 3V to DAC VCC (red wire)
-
Board STEMMA GND to DAC GND (black wire)
-
Board STEMMA SCL to DAC SCL (yellow wire)
- Board STEMMA SDA to DAC SDA (blue wire)
You can output a signal from any of the 8 DAC channels.
The following is the DAC wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V 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.
Python Computer Wiring
Since there are dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired with I2C using the STEMMA connector:
-
Pi 3V to DAC VCC (red wire)
-
Pi GND to DAC GND (black wire)
-
Pi SCL to DAC SCL (yellow wire)
- Pi SDA to DAC SDA (blue wire)
You can output a signal from any of the 8 DAC channels.
Here's the Raspberry Pi wired with I2C using a solderless breadboard:
-
Pi 3V to DAC VCC (red wire)
-
Pi GND to DAC GND (black wire)
-
Pi SCL to DAC SCL (yellow wire)
- Pi SDA to DAC SDA (blue wire)
You can output a signal from any of the 8 DAC channels.
Python Installation of DACx578 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-dacx578
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_DACx578 library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and file:
- adafruit_bus_device/
- adafruit_dacx578.mpy
Python Usage
Once you have the library pip3
installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT import math import time import board import adafruit_dacx578 # Initialize I2C and DAC i2c = board.I2C() dac = adafruit_dacx578.DACx578(i2c) MAX_VALUE = 65535 # 16-bit value BASE_FREQ = 1.0 # frequency in Hz SAMPLE_RATE = 100 # samples per second FREQ_MULTIPLIERS = [ 1.0, # Channel 0: 1 Hz 2.0, # Channel 1: 2 Hz 3.0, # Channel 2: 3 Hz 4.0, # Channel 3: 4 Hz 5.0, # Channel 4: 5 Hz 6.0, # Channel 5: 6 Hz 7.0, # Channel 6: 7 Hz 8.0, # Channel 7: 8 Hz ] def calculate_sinewave(frequency, time_point): angle = 2 * math.pi * frequency * time_point return int((math.sin(angle) + 1) * (MAX_VALUE / 2)) start_time = time.monotonic() while True: current_time = time.monotonic() - start_time for channel_num in range(8): frequency = BASE_FREQ * FREQ_MULTIPLIERS[channel_num] value = calculate_sinewave(frequency, current_time) dac.channels[channel_num].value = value time.sleep(1 / SAMPLE_RATE)
First, the DAC is instantiated over I2C. Then, in the loop, the sinewaves are written to each of the 8 DAC outputs. Each sinewave is generated at a different frequency. You can connect the outputs to your oscilloscope to measure them. In the image below, channels 0 and 2 on the DAC are connected to the two inputs on an oscilloscope. Channel 0 is operating at 1 Hz and channel 2 is operating at 3 Hz.
Page last edited March 06, 2025
Text editor powered by tinymce.