I2C: Programming 4 channel 16 bit DAC AD5696R


I need my Arduino Leonardo ETH to control a 4 channel DAC.

I don't want to use PWM because I require a very stable analog output (0-5V). Therefore I looked for a 4 channel DAC (I don't necessarily need 16 bit: 10 or 12 would be enough, but I found that nice chip and I thought with 16 bit it's easy to just send the two bytes of an uint16). Speed is not an issue: Setting a new output every half second is enough.

I decided to use the AD5696R chip with the I2C interface.

So I thought, it's very easy: Write the two bytes into the register of the DAC. Here's my code:

Wire.beginTransmission(DAC_ADDR);	 // Begin transmission to the DAC
Wire.write(DAC_CH_0);		         // Move pointer to the specified DAC channel
Wire.write(cmd[2]);			 // Write first byte.
Wire.write(cmd[3]);		         // Now second one.

Well, it's not that easy. I suspect I miss sending some "command" byte or so to the DAC. I confess, I don't fully understand that datasheet (linked, from page 19 on), so maybe one of you could help me what I am missing (I am quite confident in programming, but electronics is very new to me)? I am only sure about the first line of code: I found the correct chip address with i2cdetect of a Raspberry Pi.

As I am commited to contribute to the community: I will make that small library available to the community as soon as it is working.

Thanks a lot!
Best, Andreas

Well, it's not that easy.

Right, it is not that easy to fathom out what that code is doing exactly because you missed out the bits the define the variables so we can't see if the DAC_CH_0 variable is defined correctly. Bottom line is to post ALL your code.

Also we need to know how you have wired this chip up and what address you are expecting it to be on.

Note that their is an input register, a DAC register and a String register as well as a power down switch, see the diagram at the top of the page. So writing something out is not as simple as writing two bytes of data. You need to write those two bytes and then transfer the input register to the DAC register.

The top four bits of the first byte is the command you want to do the bottom four bits are what you want to do it to. Look at the list of commands to see what your options are.

You're right, of course - thanks for your honest feedback. I have given my question quite some thought.

The chip has the addres 0x0C.

The real problem is: I am not sure how to "build" the byte-array to send.

So, as far as I understand, I have to do the following (please correct me if I am wrong):
Send: 0 0 1 1 (= Write to and update DAC Channel A) + 0 0 0 1 (= DAC A) + DAC data ( = my 2 bytes)

Here I'd appreciate some help: (I) How do I build that byte array that I then send via Wire.write()? From the C++ point of view? (II) The DAC byte should have the order high byte, then low byte: Is that just the bytes of an uint16?

For the simple case of just having a defined voltage at each DAC channel, this should be sufficient, right? No other commands are needed for me?

I just write them with Wire.write and I am done?

Thanks again for your patience!


Send: 0 0 1 1 (= Write to and update DAC Channel A) + 0 0 0 1 (= DAC A) + DAC data ( = my 2 bytes)…
How do I build that byte array

No that is what you need to send in the first byte it is not a byte array just a byte.

The top four bits of the first byte is the command you want to do which in your case is 0 0 1 1 so if that is in a variable you would say

command = 3;

what you want to do it to is dacA

dacA = 1;

Now to join them together shift the command by four places to the left and OR it with the dac like this

send = (command <<4) | dacA ;

Or just write it out as 0011 0001

send = 0x31;


thanks a lot - that helped a lot.

So I have the beginTransmission with the address of the chip, then I send the command byte and then the uint16 as 2-byte array.

I will try that and either return with more specific errors or post my code for reuse by somebody else. Until then: Thank you!



thanks - it worked beautifully. I will post some code for others who might find it useful later, when my project is a bit more complete.

Thanks again,

1 Like

hey can you provide the code of controling that dac? thanks

Hi, wanna ask. Will code works with Audioengine D1 24-Bit?

Hi, wanna ask. Will code works with Audioengine D1 24-Bit?