user-1: I have an Arduino Mega AT2560 and need to have real DAC. I purchased the Sparkfun 12 bit DAC, however I don't think it is working properly.
I am using the Arduino wire library to communicate with the DAC. When I write 0, I am expecting to see 0v from the DAC's OUT pin. However, I see some seemingly random constant voltage. In reverse, when I write 4095 to the DAC I see the same voltage as when I write 0. I expected to see 5v.

Can someone verify that I hooked it up correctly?
Can someone verify the code I am using?


#include <stdint.h>
#include <stdio.h>
#include <Wire.h>

#define MCP4725_ADDR 0x60 // [0000 0110]
/*
* 12 Bit DAC MCP4725 gives a range of 4096 possible values.
* 
*/
void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Wire.beginTransmission(MCP4725_ADDR);
  Wire.write(64);            // cmd to update the DAC [0100 0000]
  Wire.write(4095 >> 4);        // the 8 most significant bits...
  Wire.write((4095 & 15) << 4); // the 4 least significant bits...
  Wire.endTransmission();
}


user23309: Sorry I'm late -- I realize this question was asked 8 months ago, but it doesn't look like you fixed it, and I figure others can always benefit (or you might even, if you still want to try).
Your code looks correct (I compared it to the Sparkfun example, and also to the datasheet for the MPC4725). 
However, it does look like you're using the wrong address for the part.
(The actual value for the address is not given in the Sparkfun example -- at least, I couldn't find it).
Your line:
#define MCP4725_ADDR 0x60 // [0000 0110]

is wrong in two places: 
1) 0x60 is 0110 0000, not 0000 0110
2) According to the datasheet (section 7.2), the address should begin with the device code %1100, and then the address gets appended. So assuming an address of A2 = 0, A1 = 0, and A0 = 0 (default), the value for MCP4725_ADDR looks like it should be 0xC0 or %1100 000x.  If you soldered the address line to Vcc instead of ground, the address should be 0xC2 or %1100 001x.
The x in the address line represents the read/write bit.  If you're trying to command the DAC, it should not be asserted, so the addresses above are correct. If you're trying to read the current value, it should be asserted, which makes your address 0xC1 or 0xC3.
If you have the address wrong, even though the rest is correct, the part will ignore it, so that's probably the issue you're seeing.
Hope this helps someone!

user30005: 
you want to make sure that there are pull-ups on the SCL/SDA lines;
you want to make sure that the address is correct. some routines use 7-bit notation for that, and others use 8-bit notation for that. end of the day, you want the transmission to be 0xc0 | (A2:A1:A0:R/W). so check the write.write() and see what it expects. I suspect that it expects 0xCx, rather than 0x6x.

having said that, here is your code running on an uno, with the dac configured as per sparkfun spec.

so I think it is fair to say that the code is ok but something happened on your end that prevented it from working.

-1: <p>I have an Arduino Mega AT2560 and need to have real DAC. I purchased the <a href="https://www.sparkfun.com/products/12918" rel="nofollow noreferrer">Sparkfun 12 bit DAC</a>, however I don't think it is working properly.</p>

<p>I am using the Arduino wire library to communicate with the DAC. When I write 0, I am expecting to see 0v from the DAC's OUT pin. However, I see some seemingly random constant voltage. In reverse, when I write 4095 to the DAC I see the same voltage as when I write 0. I expected to see 5v.</p>

<ol>
<li>Can someone verify that I hooked it up correctly?</li>
<li>Can someone verify the code I am using?</li>
</ol>

<p><a href="https://i.stack.imgur.com/YXl7l.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YXl7l.jpg" alt="12 Bit DAC with Arduino ATMega 2560"></a></p>

<pre><code>#include &lt;stdint.h&gt;
#include &lt;stdio.h&gt;
#include &lt;Wire.h&gt;

#define MCP4725_ADDR 0x60 // [0000 0110]
/*
* 12 Bit DAC MCP4725 gives a range of 4096 possible values.
* 
*/
void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Wire.beginTransmission(MCP4725_ADDR);
  Wire.write(64);            // cmd to update the DAC [0100 0000]
  Wire.write(4095 &gt;&gt; 4);        // the 8 most significant bits...
  Wire.write((4095 &amp; 15) &lt;&lt; 4); // the 4 least significant bits...
  Wire.endTransmission();
}
</code></pre>
 23309: <p>Sorry I'm late -- I realize this question was asked 8 months ago, but it doesn't look like you fixed it, and I figure others can always benefit (or you might even, if you still want to try).</p>

<p>Your code looks correct (I compared it to the Sparkfun example, and also to the datasheet for the MPC4725). </p>

<p>However, it does look like you're using the wrong address for the part.
(The actual value for the address is not given in the Sparkfun example -- at least, I couldn't find it).</p>

<p>Your line:</p>

<pre><code>#define MCP4725_ADDR 0x60 // [0000 0110]
</code></pre>

<p>is wrong in two places: </p>

<p>1) 0x60 is 0110 0000, not 0000 0110</p>

<p>2) According to the datasheet (section 7.2), the address should begin with the device code %1100, and then the address gets appended. So assuming an address of A2 = 0, A1 = 0, and A0 = 0 (default), the value for MCP4725_ADDR looks like it should be 0xC0 or %1100 000x.  If you soldered the address line to Vcc instead of ground, the address should be 0xC2 or %1100 001x.</p>

<p>The x in the address line represents the read/write bit.  If you're trying to command the DAC, it should not be asserted, so the addresses above are correct. If you're trying to read the current value, it should be asserted, which makes your address 0xC1 or 0xC3.</p>

<p>If you have the address wrong, even though the rest is correct, the part will ignore it, so that's probably the issue you're seeing.</p>

<p>Hope this helps someone!</p>
 30005: <ol>
<li>you want to make sure that there are pull-ups on the SCL/SDA lines;</li>
<li>you want to make sure that the address is correct. some routines use 7-bit notation for that, and others use 8-bit notation for that. end of the day, you want the transmission to be 0xc0 | (A2:A1:A0:R/W). so check the write.write() and see what it expects. I suspect that it expects 0xCx, rather than 0x6x.</li>
</ol>

<p>having said that, here is your code running on an uno, with the dac configured as per sparkfun spec.</p>

<p><a href="https://i.stack.imgur.com/2skTO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2skTO.png" alt="enter image description here"></a></p>

<p>so I think it is fair to say that the code is ok but something happened on your end that prevented it from working.</p>
