Multiple MCP4725s

I am having a problem getting two MCP4725s to output analogue voltage

I have made an extract from my larger code to trouble shoot the DACs but this very simple code stops before executing the dac.setvoltage command.

Code is :

#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;

int iwhite; //I2C input for white output
int ibrown; //I2C input for brown output

void setup() {
Serial.begin(4800);
Wire.begin();
}

void loop() {
iwhite = 2000;
ibrown = 3000;
Serial.println("iwhite =");
Serial.println(iwhite);
Serial.println("ibrown =");
Serial.println(ibrown);

//write to adafruit DAC for brown wire
dac.begin(0x63);
{
dac.setVoltage(ibrown, false);
}

//write to adafruit DAC for white wire

dac.begin(0x62);
{
dac.setVoltage(iwhite, false);
}

Serial.println("done setting DACs to correct voltages");

Anything obvious that i am doing wrong?

Your code is incomplete

Correction

I left it out of my post, but obviously, my code has the "}" to close the loop.

And obviously, you forgot the code tags.

Did you run the I2CScanner sketch to verify there are devices at those addresses?

dac.begin() and dacSetVoltage() both return true/false for success/error - why are you not checking them?

A more common method of use would be to create 2 instances, one at each address and have the .begin() moved into setup().

Is the DAC pin A0 wired properly?

thanks very much. a big help. the scanner indicates that one of the boards is not responding. when i switch the I2c addressing the same board still does not respond so i am pretty sure its a problem with the baord. thanks again

thanks for response. i checked that and it seems ok.

Are you running the scanner sketch with only 1 board connected? You can't have two devices on the i2c bus with the same address. Make sure you are verifying each board separately without the other connected.

Thanks. I ran the scanner sketch with each board separately. One works as expected and the other not at all, both wired identically. Pretty sure one board is bad.

May seem like a dumb question, but could you please advise generally how (or what code I should use) to check the value being returned from dac.begin() and dacSetVoltage() as true or false?

if ( dac.begin() == true ) {
  Serial.println("DAC begin was successful");
}
else {
  Serial.println("DAC begin failed");
}

Thanks very much.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.