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