The Adafruit MCP4728 is a versatile and precise multi-channel digital-to-analog converter (DAC) module. It is equipped with four independent 12-bit DAC channels, enabling the conversion of digital signals into analog voltages. This module is ideal for applications requiring multiple analog outputs, such as generating audio signals, controlling variable lighting, or driving analog sensors. It interfaces with microcontrollers via the I2C protocol, making it a convenient addition to projects that require analog capabilities but are limited to digital-only outputs.
Pin Number | Pin Name | Description |
---|---|---|
1 | VDD | Power supply (2.7V to 5.5V) |
2 | GND | Ground |
3 | SCL | I2C clock line |
4 | SDA | I2C data line |
5 | A0 | Address select bit 0 (I2C address pin) |
6 | A1 | Address select bit 1 (I2C address pin) |
7 | A2 | Address select bit 2 (I2C address pin) |
8 | VOUTA | Analog output for DAC channel A |
9 | VOUTB | Analog output for DAC channel B |
10 | VOUTC | Analog output for DAC channel C |
11 | VOUTD | Analog output for DAC channel D |
#include <Wire.h>
#include <Adafruit_MCP4728.h>
Adafruit_MCP4728 mcp;
void setup() {
Wire.begin(); // Start I2C bus
mcp.begin(0x60); // Initialize MCP4728, default address 0x60
// Set the voltage output of all channels to mid-scale
mcp.setChannelValue(MCP4728_CHANNEL_A, 2048);
mcp.setChannelValue(MCP4728_CHANNEL_B, 2048);
mcp.setChannelValue(MCP4728_CHANNEL_C, 2048);
mcp.setChannelValue(MCP4728_CHANNEL_D, 2048);
mcp.saveToEEPROM(); // Save the current settings to EEPROM
}
void loop() {
// Example: Cycle through voltage levels on channel A
for (uint16_t i = 0; i < 4096; i++) {
mcp.setChannelValue(MCP4728_CHANNEL_A, i);
delay(10);
}
}
Wire.endTransmission()
function to check for I2C errors. A return value of 0 indicates success.Q: Can I use the MCP4728 with a 3.3V system? A: Yes, the MCP4728 can operate at voltages as low as 2.7V.
Q: How do I change the I2C address of the MCP4728? A: The I2C address can be changed by adjusting the A0, A1, and A2 pins.
Q: Can I save the DAC output values so they persist after power cycling?
A: Yes, the saveToEEPROM()
function will store the current DAC values to the internal EEPROM.
Q: Is it possible to update all DAC channels simultaneously? A: Yes, the MCP4728 supports a multi-write command to update all channels at once.