Simple test

Ensure your device works with this simple test.

examples/dacx578_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import board
 6
 7import adafruit_dacx578
 8
 9i2c = board.I2C()
10dac = adafruit_dacx578.DACx578(i2c)
11
12# channels are available with dac.channels[NUM]
13# with NUM being 0-7
14dac.channels[0].value = 65535  # 3.3V
15dac.channels[1].value = int(65535 / 2)  # 1.65V
16dac.channels[2].value = int(65535 / 4)  # 0.825V
17dac.channels[3].value = 0

Sinewave test

Generate sinewaves on each channel

examples/dacx578_sinewaves.py
 1# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import math
 5import time
 6
 7import board
 8
 9import adafruit_dacx578
10
11# Initialize I2C and DAC
12i2c = board.I2C()
13dac = adafruit_dacx578.DACx578(i2c)
14
15MAX_VALUE = 65535  # 16-bit value
16BASE_FREQ = 1.0  # frequency in Hz
17SAMPLE_RATE = 100  # samples per second
18
19FREQ_MULTIPLIERS = [
20    1.0,  # Channel 0: 1 Hz
21    2.0,  # Channel 1: 2 Hz
22    3.0,  # Channel 2: 3 Hz
23    4.0,  # Channel 3: 4 Hz
24    5.0,  # Channel 4: 5 Hz
25    6.0,  # Channel 5: 6 Hz
26    7.0,  # Channel 6: 7 Hz
27    8.0,  # Channel 7: 8 Hz
28]
29
30
31def calculate_sinewave(frequency, time_point):
32    angle = 2 * math.pi * frequency * time_point
33    return int((math.sin(angle) + 1) * (MAX_VALUE / 2))
34
35
36start_time = time.monotonic()
37
38while True:
39    current_time = time.monotonic() - start_time
40
41    for channel_num in range(8):
42        frequency = BASE_FREQ * FREQ_MULTIPLIERS[channel_num]
43        value = calculate_sinewave(frequency, current_time)
44        dac.channels[channel_num].value = value
45
46    time.sleep(1 / SAMPLE_RATE)