Simple test

Ensure your device works with this simple test.

examples/mcp4728_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import adafruit_mcp4728

i2c = board.I2C()  # uses board.SCL and board.SDA
mcp4728 = adafruit_mcp4728.MCP4728(i2c)

mcp4728.channel_a.value = 65535  # Voltage = VDD
mcp4728.channel_b.value = int(65535 / 2)  # VDD/2
mcp4728.channel_c.value = int(65535 / 4)  # VDD/4
mcp4728.channel_d.value = 0  # 0V

Vref Example

Example showing the way to work with Vref

examples/examples/mcp4728_vref_example.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

from time import sleep
import board
import adafruit_mcp4728

i2c = board.I2C()  # uses board.SCL and board.SDA
mcp4728 = adafruit_mcp4728.MCP4728(i2c)

FULL_VREF_RAW_VALUE = 4095

# pylint: disable=no-member
mcp4728.channel_a.raw_value = int(FULL_VREF_RAW_VALUE / 2)  # VDD/2
mcp4728.channel_a.vref = (
    adafruit_mcp4728.Vref.VDD
)  # sets the channel to scale between 0v and VDD

mcp4728.channel_b.raw_value = int(FULL_VREF_RAW_VALUE / 2)  # VDD/2
mcp4728.channel_b.vref = adafruit_mcp4728.Vref.INTERNAL
mcp4728.channel_b.gain = 1

mcp4728.channel_c.raw_value = int(FULL_VREF_RAW_VALUE / 2)  # VDD/2
mcp4728.channel_c.vref = adafruit_mcp4728.Vref.INTERNAL
mcp4728.channel_c.gain = 2

mcp4728.save_settings()

while True:
    sleep(1)

General Call Example

Example showing the way to work with General Calls

examples/examples/mcp4728_generalcalltest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# SPDX-FileCopyrightText: 2021 codenio (Aananth K)
# SPDX-License-Identifier: MIT

import board
import adafruit_mcp4728

i2c = board.I2C()  # uses board.SCL and board.SDA
mcp4728 = adafruit_mcp4728.MCP4728(i2c)

mcp4728.channel_a.value = 65535  # Voltage = VDD
mcp4728.channel_b.value = int(65535 / 2)  # VDD/2
mcp4728.channel_c.value = int(65535 / 4)  # VDD/4
mcp4728.channel_d.value = 0  # 0V

mcp4728.save_settings()  # save current voltages into EEPROM
print("Settings Saved into EEPROM")

input("Press Enter to modify the channel outputs...")

mcp4728.channel_a.value = 0  # Modify output
mcp4728.channel_b.value = 0  # Modify output
mcp4728.channel_c.value = 0  # Modify output
mcp4728.channel_d.value = 65535  # Modify output

print("Channel Outputs Modified")

input("Press Enter to invoke General Call Reset ...")

mcp4728.reset()  # reset MCP4728