#include <Adafruit_MCP4728.h>
#include <Wire.h>
Adafruit_MCP4728 mcp;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MCP4728 test!");
// Try to initialize!
if (!mcp.begin()) {
Serial.println("Failed to find MCP4728 chip");
while (1) {
delay(10);
}
}
mcp.setChannelValue(MCP4728_CHANNEL_A, 895);
mcp.setChannelValue(MCP4728_CHANNEL_B, 2048);
mcp.setChannelValue(MCP4728_CHANNEL_C, 1024);
mcp.setChannelValue(MCP4728_CHANNEL_D, 500);
}
void loop() { delay(1000); }
I see “Adafruit MCP4728 test!” in the serial output and I don’t see “Failed to find MCP4728 chip”.
But there is no voltage at the A,B,C,D outputs. What might be wrong?
I am assuming the device communicates via IIC… if so the default pins for SDA is 4 and SCL is 5
also code weitten for arduino Uno sometimes do not set up the comms right… you would need to dig into the LIB to understand what is happening under the hood
You are right. It works with pins D4 and D5. I was totally misled by this bug in the “Wire” library. If the I2C device isn’t connected to the SDA and SCLK pins at all (these pins of the microcontroller were open), then the library call to mcp.begin() doesn’t return any error message. That’s why I didn’t see the “Failed to find MCP4728 chip” message. It did look like a successful connection, but it wasn’t connected at all.
I have one additional question. In the above schematic the MCP4728 has 5V supply voltage. SCL is an input pin, that’s no problem. SDA is an I/O pin with open collector and 8.2kOhm pullup to 5V. That means a small current is flowing into the input clamp diode of the SAMD21: (5V - 3.3V) / 8200 = 0.21mA
Is this acceptable?
In the SAMD21 datasheet I didn’t find a specification for the maximum current of the clamp diodes.
Am I right to assume the pins have clamp diodes?
I only found a voltage specification in chapter 37.2: Maximum pin voltage is VDD + 0.3V.
I don’t think the performance of the clamp diode will be published. Increasing the resistance increases safety, but requires slower communication speed. What about using a level shifter?