I am using an AD5693 as digital to analog converter with an Arduino Uno. I have connected the SDA andSCL pins of the AD5693 to the I2C pins of the Arduino Uno. I have connected the LDAC active low to gnd. The reset pin is connected to VDD.

I got the example code from GitHub.

The below code works properly:


// AD5693 I2C address is 0x4C(76)

#define Addr 0x4C

void setup()

  // Initialise I2C communication as Master


  // Initialise serial communication, set baud rate = 9600




void loop()

unsigned int data[2] = {0x80, 0x00};

  // Start I2C transmission
// Select DAC and input register
// Write data = 0x8000(32768)
 // data msb = 0x80
// data lsb = 0x00
 // Stop I2C transmission

  // Convert the data, Vref = 5 V
 float voltage = (((data[0] * 256) + (data[1])) / 65536.0) * 5.0;

// Output data to serial monitor
Serial.print("Voltage : ");
 Serial.println(" V");


I want to take an input from user which is an analog voltage value and the same value should be the output of the DAC IC.

Do I need to convert the the analog voltage value from the user to hexadecimal? Is there any other way.

  • \$\begingroup\$ Isn't the number you need just data[1]? \$\endgroup\$ Jul 1 '21 at 15:20
  • \$\begingroup\$ basically if i give user input as 2.1 , i want to get the same voltage at the output of the AD5693.so how will i convert the 2.1 to proportional hex value to store it in data array?@ScottSeidman \$\endgroup\$ Jul 1 '21 at 15:23

Hex or not does not matter, but you do have to convert the number from Volts to DAC units. This is because the DAC has no idea about absolute voltages, everything is proportional to its reference voltage (here 5V? But this depends on your circuit. One version of this chip has an internal 2.5V reference, the other has a pin to take an external voltage).

The datasheet gives you the formula on page 19, but it's the wrong way around:

\$ V = V_{ref} \times Gain \times \frac{code}{65536}\$

So the first step is to invert this:

\$ code = 65536 \times \frac{V}{V_{ref} \times Gain}\$

And make sure the value is of integer type, not greater than 65535 (not 65536!), and not lower than 0.

Now comes the second trick: code is a 16 bit number, and the DAC expects it in two "words" of 8 bits each:

  • first the upper 8 bits: msb = (code >> 8) & 0xFF
  • then the lower 8 bits: lsb = code & 0xFF

So you must write these two values in succession.

Assume the gain is 1 by default, but this can be changed in the DAC's config.

  • \$\begingroup\$ thanks you for advice @DamienD \$\endgroup\$ Jul 2 '21 at 5:04

A number is a number. You can represent the any number in different ways, it will still be the same number in any representation, either in binary, in hexadecimal, in octal, or decimal.

So no, it does not need to be converted into anything. If you can read a number that the user enters somehow into a variable, it needs no conversion.

  • \$\begingroup\$ thanks for advice @Justme \$\endgroup\$ Jul 2 '21 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.