Simple test

Ensure your device works with this simple test. Write individual values to all DAC channels from a list.

examples/ltc166x_dac_value_list.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Thadeus Frazier-Reed for creativecontrol
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6"""
 7Write individual values to all DAC channels from a list.
 8"""
 9
10import time
11import board
12import creativecontrol_circuitpython_ltc166x
13
14ltc1665 = creativecontrol_circuitpython_ltc166x.LTC1665(
15    csel=board.GP1, sck=board.GP2, mosi=board.GP3, debug=True
16)
17
18dac_values = [1, 3, 7, 15, 31, 63, 127, 255]
19
20while True:
21    print("writing dac values ", time.monotonic())
22    ltc1665.write_dac_values(dac_values)
23    time.sleep(4)
24    print("off")
25    ltc1665.write_dac_values([0] * 8)
26    time.sleep(4)

Single value

Write a value to a single DAC channel.

examples/ltc166x_single_value.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Thadeus Frazier-Reed for creativecontrol
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6"""
 7Write a value to a single DAC channel.
 8"""
 9
10import time
11import board
12import creativecontrol_circuitpython_ltc166x
13
14ltc1665 = creativecontrol_circuitpython_ltc166x.LTC1665(
15    csel=board.GP1, sck=board.GP2, mosi=board.GP3, debug=True
16)
17
18dac = ltc1665.DAC_A
19dac_value = 127
20
21while True:
22    print("writing dac value ", time.monotonic())
23    ltc1665.write_dac_value(dac_value, dac)
24    time.sleep(4)
25    print("off")
26    ltc1665.write_dac_value(0, dac)
27    time.sleep(4)

Single value sweep

Write a value to a single DAC channel ramping from min to max and back.

examples/ltc166x_single_value_sweep.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Thadeus Frazier-Reed for creativecontrol
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6"""
 7Write a value to a single DAC channel ramping from min to max and back.
 8"""
 9
10import time
11import board
12import creativecontrol_circuitpython_ltc166x
13
14ltc1665 = creativecontrol_circuitpython_ltc166x.LTC1665(
15    csel=board.GP1, sck=board.GP2, mosi=board.GP3, debug=True
16)
17
18dac = ltc1665.DAC_A
19dac_value = 0
20direction = 1
21
22while True:
23    print("writing dac value ", time.monotonic())
24    ltc1665.write_dac_value(dac_value, dac)
25    time.sleep(0.01)
26    dac_value += 1 * direction
27    if 0 >= dac_value or dac_value >= ltc1665.get_device_range() - 1:
28        direction *= -1

DAC list selective

Write random values to all DAC channels from a list. Only update value if it has changed.

examples/ltc166x_dac_list_selective.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Thadeus Frazier-Reed for creativecontrol
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6"""
 7Write random values to all DAC channels from a list. Only update value if it has changed.
 8"""
 9
10import random
11import time
12import board
13import creativecontrol_circuitpython_ltc166x
14
15ltc1665 = creativecontrol_circuitpython_ltc166x.LTC1665(
16    csel=board.GP1, sck=board.GP2, mosi=board.GP3, debug=True
17)
18
19dac_values = [1, 3, 7, 15, 31, 63, 127, 255]
20last_values = []
21
22while True:
23    print("writing dac values ", time.monotonic())
24    ltc1665.write_dac_values(dac_values)
25    time.sleep(4)
26    print("off")
27    ltc1665.write_dac_values([0] * 8)
28    time.sleep(4)
29    last_values = dac_values.copy()
30    for index, _ in enumerate(dac_values):
31        dac_values[index] = random.randint(0, ltc1665.get_device_range() - 1)
32        if dac_values[index] == last_values[index]:
33            dac_values[index] = -1

DAC Chain

Example of using a DAC daisy-chain as described in the LTC166X datasheet https://www.analog.com/media/en/technical-documentation/data-sheets/166560fa.pdf

examples/ltc166x_dac_chain.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Thadeus Frazier-Reed for creativecontrol
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6"""
 7Example of using a DAC daisy-chain as described in the LTC166X datasheet
 8https://www.analog.com/media/en/technical-documentation/data-sheets/166560fa.pdf
 9"""
10
11import time
12import board
13import creativecontrol_circuitpython_ltc166x
14
15ltc1665 = creativecontrol_circuitpython_ltc166x.LTC1665(
16    csel=board.GP1, sck=board.GP2, mosi=board.GP3, debug=True
17)
18
19dac_values = [[1, 3, 7, 15, 31, 63, 127, 255], [255, 127, 63, 31, 15, 7, 3, 1]]
20
21while True:
22    print("writing dac values ", time.monotonic())
23    ltc1665.write_chained_dac_values(dac_values)
24    time.sleep(4)
25    print("off")
26    ltc1665.write_chained_dac_values([[0] * 8, [0] * 8])
27    time.sleep(4)