adafruit_mcp4728

Helper library for the Microchip MCP4728 I2C 12-bit Quad DAC

  • Author(s): Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_mcp4728.MCP4728(i2c_bus, address=96)

Helper library for the Microchip MCP4728 I2C 12-bit Quad DAC.

Parameters:
  • i2c_bus (I2C) – The I2C bus the MCP4728 is connected to.
  • address (int) – The I2C device address. Defaults to 0x60

Quickstart: Importing and using the MCP4728

Here is an example of using the MCP4728 class. First you will need to import the libraries to use the sensor

import board
import adafruit_mcp4728

Once this is done you can define your board.I2C object and define your sensor object

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

Now you have can give values to the different channels

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
save_settings()

Saves the currently selected values, Vref, and gain selections for each channel to the EEPROM, setting them as defaults on power up

sync_vrefs()

Syncs the driver’s vref state with the DAC

sync_gains()

Syncs the driver’s gain state with the DAC

reset()

Internal Reset similar to a Power-on Reset (POR). The contents of the EEPROM are loaded into each DAC input and output registers immediately

wakeup()

Reset the Power-Down bits (PD1, PD0 = 0,0) and Resumes Normal Operation mode

soft_update()

Updates all DAC analog outputs (VOUT) at the same time.

class adafruit_mcp4728.Channel(dac_instance, cache_page, index)

An instance of a single channel for a multi-channel DAC.

Parameters:
  • dac_instance – Instance of the channel object
  • cache_page – cache page of the channel
  • index – Index of the channel

Note

All available channels are created automatically and should not be created by the user

normalized_value

The DAC value as a floating point number in the range 0.0 to 1.0.

value

The 16-bit scaled current value for the channel. Note that the MCP4728 is a 12-bit piece so quantization errors will occur

raw_value

The native 12-bit value used by the DAC

gain

Sets the gain of the channel if the Vref for the channel is Vref.INTERNAL. The gain setting has no effect if the Vref for the channel is `Vref.VDD`.

With gain set to 1, the output voltage goes from 0v to 2.048V. If a channel’s gain is set to 2, the voltage goes from 0V to 4.096V. gain Must be 1 or 2

vref

Sets the DAC’s voltage reference source. Must be a VREF