DAC MCP4725 hangs on setVoltage

Hello everyone!

I needed a dac to send analog signals through a cable, so I bought a MCP4725. Unfortunately it came as a 3 x 2 mm chip, so to make it possible to connect to arduino I asked my friend to solder it(the "soldered wires" seem to be working correctly). I wrote what does each pin do according to the datasheet. I think it is labeled correctly (on the picture where you can see the chip, the letters on the chip are upside down). Then I have wired it exactly this same as on Overview | MCP4725 12-Bit DAC Tutorial | Adafruit Learning System and used the same library, but when I launched the trianglewave example or any other code using dac, arduino always hangs on setVoltage method.

My question is, why doesn't it work and what am I doing wrong?

Here are the pictures of my circuit and the chip:
DAC board: Dropbox - Error - Simplify your life
Circuit: Dropbox - Error - Simplify your life
The yellow cable is my output. I tried connecting it to the led, using resistor and then to ground, but I get no difference.
Link to the library: https://github.com/adafruit/Adafruit_MCP4725/archive/master.zip
Link to the datasheet: https://www.sparkfun.com/datasheets/BreakoutBoards/MCP4725.pdf

tranglewave code:

/**************************************************************************/
/*! 
    @file     trianglewave.pde
    @author   Adafruit Industries
    @license  BSD (see license.txt)

    This example will generate a triangle wave with the MCP4725 DAC.   

    This is an example sketch for the Adafruit MCP4725 breakout board
    ----> https://www.adafruit.com/products/???
 
    Adafruit invests time and resources providing this open source code, 
    please support Adafruit and open-source hardware by purchasing 
    products from Adafruit!
*/
/**************************************************************************/
#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

void setup(void) {
  Serial.begin(9600);
  Serial.println("Hello!");

  // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
  // For MCP4725A0 the address is 0x60 or 0x61
  // For MCP4725A2 the address is 0x64 or 0x65
  dac.begin(0x62);
    
  Serial.println("Generating a triangle wave");
}

void loop(void) {
    uint32_t counter;
    // Run through the full 12-bit scale for a triangle wave
    for (counter = 0; counter < 4095; counter++)
    {
      dac.setVoltage(counter, false);
    }
    for (counter = 4095; counter > 0; counter--)
    {
      dac.setVoltage(counter, false);
    }
}

Thanks for any help :slight_smile:

I suspect the answer lies in the code:

// For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
  // For MCP4725A0 the address is 0x60 or 0x61
  // For MCP4725A2 the address is 0x64 or 0x65
  dac.begin(0x62);

Have you tried other addresses?

No, I have not, I will try it right away. Should I plug A0 to Vcc(it's Vdd on my circuit I suppose), as it is said on the website?

edit1: I have tried it with addresses from 0x60 to 0x65 with no success. I have connected the 5v, Vcc and A0 together and retried with no success too. Any other ideas? Just out of curiosity, is there a way to see if I correctly labeled the ports on the board?

mafiu95:
No, I have not, I will try it right away. Should I plug A0 to Vcc(it's Vdd on my circuit I suppose), as it is said on the website?

Only if you want the address to be 0x63.

Note: in this case, A0 refers to the A0 pin on the module, not the A0 pin on the Arduino.

mafiu95:
edit1: I have tried it with addresses from 0x60 to 0x65 with no success. I have connected the 5v, Vcc and A0 together and retried with no success too. Any other ideas? Just out of curiosity, is there a way to see if I correctly labeled the ports on the board?

Yes, I did use the A0 on the board, not on the arduino. Still I don't get any results...

According to the datasheet you posted the link to, you have the version that has A0 exposed.
So your options are:

Connect that pin to gnd (of the DAC) and use dac.begin(0x60);
or
Connect that pin to Vcc (of the DAC) and use dac.begin(0x61);

If it does not work, recheck your connections.

EDIT:

I assume that you are switching off power to the DAC before changing it's address pin for two reasons:

  1. It's safer.
  2. I don't know if the DAC reads the hardware address only at power up or every time it gets a command.

Just out of interest, connect A0 (of the DAC) to ground and try:

dac.begin(0xC0);

Still no change. Code always hangs on setVoltage method and nothing happens. If comeone could check if I am right, if you look at the dac circuit picture (Dropbox - Error - Simplify your life) the port numbers should go in the following order:
From the upper left corner the pin no. is 6 then 5 then 4 and from lower left corner it is 3 then 2 then 1. The only clue about the pin numbers is the text printed on the board, on the picture I gave the link to earlier the text would be upside down.

I still think it is something wrong with a code, but I want to be sure. I did restarted dac, by simply removing the 5v cable from breadboard, flashing arduino and putting the cable back. Is it the right way?

It's very difficult to try and see which is pin 1 on the DAC from that picture and also which of the tracks coming from the DAC go to which pins on your Arduino.
Can you edit that picture by adding text to it indicating that information and uploading to dropbox again?

From the upper left corner the pin no. is 6 then 5 then 4 and from lower left corner it is 3 then 2 then 1. The only clue about the pin numbers is the text printed on the board, on the picture I gave the link to earlier the text would be upside down.

Actually, the best clue is that the little notch on the chip signifies the end that pin 1 is on. if you look at the chip from above, with the notch away from you, pin 1 is the one on the left, just like it's shown on the datasheet where it show the package type .

lar3ry:
Actually, the best clue is that the little notch on the chip signifies the end that pin 1 is on. if you look at the chip from above, with the notch away from you, pin 1 is the one on the left, just like it's shown on the datasheet where it show the package type .

I knew about it, but it seems my chip does not simply have it. However, on one side (right side on the previous picture of just the circuit) you can see a very small piece of wire or something similar. You can see it clearly on this picture: Dropbox - Error - Simplify your life

Please see attached pic and confirm if correct and if so which pins on your Arduino do the SCL and SDA lines go?
Also solder a capacitor of 100 - 220nF between pins 2 and 3 of the DAC as it will aid in decoupling.

SDA goes to pin A4, while SCL goes to pin A5 both on arduino. Unfortunately I don't think I have any spare capacitors right now.

I have tried to make the pictures more clear:

DAC chip: Dropbox - Error - Simplify your life
DAC chip connected to arduino through breadboard: Dropbox - Error
The wire (?) on side of a DAC chip: Dropbox - Error - Simplify your life

Unfortunately, I got to go to sleep, as it is after midnight in here, I should be back after 15hrs GMT, then I would be able to do any testing and replying.

Your connections seem right, are you sure that the DAC was not overheated when soldered on?

Try get the capacitor and we try again tomorrow.

I don't think so, actually it was glued to the board and the connections. It is quite hard for me to get the capacitor right now, as the electronic store is quite far from my daily route :(. I will try to get it to this weekend anyway.

I've got an idea. Let's say that I used the wrong sides of the dac chip and mislabeled the ports. If I try to change it, could that break the chip, assuming that I did connected it correctly in the first place?

mafiu95:
I've got an idea. Let's say that I used the wrong sides of the dac chip and mislabeled the ports. If I try to change it, could that break the chip, assuming that I did connected it correctly in the first place?

Depends on how you try to make the change. You already have it soldered to the board, and the traces bring the pins out to holes. The safest way is to just unplug everything from the Arduino and replug the wires to whatever configuration you think is right.

It's not completely safe, of course, because if it's wrong now, you may have destroyed the chip, and it it's right now, you may destroy it when you change it and plug it in. I say "you may", because it isn't a sure thing. Some chips are more tolerant than others, of miswiring.

Luckily, there are only two ways the chip can be oriented.

        1        6
        2        5
        3        4

or

        4        3
        5        2
        6        1