mcp48xx¶
Helper library for the Microchip MCP4801, MCP4811, MCP4821, MCP4802, MCP4812, and MCP4822 digital to analog converters.
Author(s): Steffen Kreutz
Implementation Notes¶
Hardware:
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
- class mcp48xx.Channel(index: int, resolution: Literal[8, 10, 12], dac: _DAC)¶
An instance of a single channel for a multi-channel DAC.
- Parameters:
dac_instance – Instance of the channel object
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 DAC does not support 16-bit values so quantization errors will occur.
- class mcp48xx.MCP4801(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4801 SPI 8-bit DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4801 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4801 chip select line is connected to.
Quickstart: Importing and using the MCP4801
Here is an example of using the
MCP4801class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4801 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4801 = mcp48xx.MCP4801(spi, cs)
Now you can give values to the DAC
mcp4801.value = 65535 # Voltage = 2.048 (if gain=1)
- property active: bool¶
The shutdown state of the channel.
With active set to True, the output voltage will be available. If it is set to False, the output will be connected to a high resistance load and a voltage will not be available.
- property gain: Literal[1, 2]¶
The gain of the channel.
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.
gainmust be 1 or 2.
- class mcp48xx.MCP4811(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4811 SPI 10-bit DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4811 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4811 chip select line is connected to.
Quickstart: Importing and using the MCP4811
Here is an example of using the
MCP4811class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4811 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4811 = mcp48xx.MCP4811(spi, cs)
Now you can give values to the DAC
mcp4811.value = 65535 # Voltage = 2.048 (if gain=1)
- property active: bool¶
The shutdown state of the channel.
With active set to True, the output voltage will be available. If it is set to False, the output will be connected to a high resistance load and a voltage will not be available.
- property gain: Literal[1, 2]¶
The gain of the channel.
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.
gainmust be 1 or 2.
- class mcp48xx.MCP4821(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4821 SPI 12-bit DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4821 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4821 chip select line is connected to.
Quickstart: Importing and using the MCP4821
Here is an example of using the
MCP4821class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4821 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4821 = mcp48xx.MCP4821(spi, cs)
Now you can give values to the DAC
mcp4821.value = 65535 # Voltage = 2.048 (if gain=1)
- property active: bool¶
The shutdown state of the channel.
With active set to True, the output voltage will be available. If it is set to False, the output will be connected to a high resistance load and a voltage will not be available.
- property gain: Literal[1, 2]¶
The gain of the channel.
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.
gainmust be 1 or 2.
- class mcp48xx.MCP4802(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4802 SPI 8-bit Dual DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4802 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4802 chip select line is connected to.
Quickstart: Importing and using the MCP4802
Here is an example of using the
MCP4802class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4802 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4802 = mcp48xx.MCP4802(spi, cs)
Now you can give values to the different channels
mcp4802.channel_a.value = 65535 # Voltage = 2.048 (if gain=1) mcp4802.channel_b.value = int(65535 / 2) # Voltage = 1.024 (if gain=1)
- class mcp48xx.MCP4812(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4812 SPI 10-bit Dual DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4812 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4812 chip select line is connected to.
Quickstart: Importing and using the MCP4812
Here is an example of using the
MCP4812class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4812 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4812 = mcp48xx.MCP4812(spi, cs)
mcp4812.channel_a.value = 65535 # Voltage = 2.048 (if gain=1) mcp4812.channel_b.value = int(65535 / 2) # Voltage = 1.024 (if gain=1)
- class mcp48xx.MCP4822(spi_bus: busio.SPI, chip_select: digitalio.DigitalInOut, latch_input: digitalio.DigitalInOut | None = None)¶
Helper class for the Microchip MCP4822 SPI 12-bit Dual DAC.
- Parameters:
spi_bus (SPI) – The SPI bus the MCP4822 is connected to.
chip_select (digitalio.DigitalInOut) – Board pin the MCP4822 chip select line is connected to.
Quickstart: Importing and using the MCP4822
Here is an example of using the
MCP4822class. First you will need to import the libraries to use the DACimport board import busio import digitalio import mcp48xx
Once this is done you can define your
board.SPIobject and define your sensor objectspi = busio.SPI(board.SCK, board.MOSI) # The MCP4822 has no MISO pin cs = digitalio.DigitalInOut(board.IO1) mcp4822 = mcp48xx.MCP4822(spi, cs)
Now you can give values to the different channels
mcp4822.channel_a.value = 65535 # Voltage = 2.048 (if gain=1) mcp4822.channel_b.value = int(65535 / 2) # Voltage = 1.024 (if gain=1)