Simple test

Ensure your device works with this simple test.

examples/mcp4725_simpletest.py
 1# SPDX-FileCopyrightText: 2018 Tony DiCola for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of setting the DAC value up and down through its entire range
 5# of values.
 6import board
 7import busio
 8
 9import adafruit_mcp4725
10
11
12# Initialize I2C bus.
13i2c = busio.I2C(board.SCL, board.SDA)
14
15# Initialize MCP4725.
16dac = adafruit_mcp4725.MCP4725(i2c)
17# Optionally you can specify a different addres if you override the A0 pin.
18# amp = adafruit_max9744.MAX9744(i2c, address=0x63)
19
20# There are a three ways to set the DAC output, you can use any of these:
21dac.value = 65535  # Use the value property with a 16-bit number just like
22# the AnalogOut class.  Note the MCP4725 is only a 12-bit
23# DAC so quantization errors will occur.  The range of
24# values is 0 (minimum/ground) to 65535 (maximum/Vout).
25
26dac.raw_value = 4095  # Use the raw_value property to directly read and write
27# the 12-bit DAC value.  The range of values is
28# 0 (minimum/ground) to 4095 (maximum/Vout).
29
30dac.normalized_value = 1.0  # Use the normalized_value property to set the
31# output with a floating point value in the range
32# 0 to 1.0 where 0 is minimum/ground and 1.0 is
33# maximum/Vout.
34
35# Main loop will go up and down through the range of DAC values forever.
36while True:
37    # Go up the 12-bit raw range.
38    print("Going up 0-3.3V...")
39    for i in range(4095):
40        dac.raw_value = i
41    # Go back down the 12-bit raw range.
42    print("Going down 3.3-0V...")
43    for i in range(4095, -1, -1):
44        dac.raw_value = i