adafruit_mcp4728
¶
Helper library for the Microchip MCP4728 I2C 12-bit Quad DAC
Author(s): Bryan Siepert
Implementation Notes¶
Hardware:
Adafruit’s MCP4728 Breakout: https://adafruit.com/product/4728
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- class adafruit_mcp4728.MCP4728(i2c_bus: I2C, address: int = 96)¶
Helper library for the Microchip MCP4728 I2C 12-bit Quad DAC.
- Parameters:
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 sensorimport board import adafruit_mcp4728
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = 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() None ¶
Saves the currently selected values, Vref, and gain selections for each channel to the EEPROM, setting them as defaults on power up
- class adafruit_mcp4728.Channel(dac_instance: Literal[0, 1, 2, 3], cache_page: Dict[str, int], index: int)¶
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
- property value: int¶
The 16-bit scaled current value for the channel. Note that the MCP4728 is a 12-bit piece so quantization errors will occur
- property gain: Literal[1, 2]¶
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