Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Communicating to dac through netduino

  • Please log in to reply
3 replies to this topic

#1 walid14


    New Member

  • Members
  • Pip
  • 3 posts

Posted 12 December 2014 - 04:29 PM

I want to use the netduino to ouptu a certain voltage through a dac121c085. Here is my code


amespace DAC_circuit
    public class Program
        public static void Main()
            //// write your code here
            I2CDevice slave = null;
            byte addr = 0x0C;
            int registerValue = 1228;       // 3V @ output
            byte[] registerValues = BitConverter.GetBytes(registerValue);
            byte[] data = BitConverter.GetBytes(registerValue);
            slave = new I2CDevice(new I2CDevice.Configuration(addr, 400));
            ////while (true)
            I2CDevice.I2CTransaction[] sendData = new I2CDevice.I2CTransaction[]
            int bytesRead = slave.Execute(sendData, 400);
            Thread.Sleep(500);      //pauses the processor for 500ms which is half a second
I want to get an output of 3V on the dac and so far when I measure it it is at 4.5v for some reason. Anyone knows how to fix this?

#2 Zoot


    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 13 December 2014 - 04:08 PM

A little more information is in order before we can help...


1.  What voltage are you using for Vref?

2.  Where did you get the integer 1228 from?  Is it calculated from the equation Vout = Vref * (D/4096)?

3.  byte [] registerValues is never used in the code snippet.  Is it used somewhere else?  If so, can you post the rest of the code?

#3 Spiked


    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 13 December 2014 - 09:16 PM

His registerValues  is exactly the same as data , since they are both created the same way. I suspect it is left over unused testing code.


The main function, does not loop. It simply Sleeps 1/2 second and ends, I guess to give time for the i2c transaction to complete?. I am unsure what the device you are using does when the i2c line closes.


I have always had to use an i2c kickstart in my code;

            // required i2c kick
            OutputPort p = new OutputPort(Pins.GPIO_PIN_SDA, true); p.Write(false); p.Dispose();
Don't you have to tell it what register you are writing to?
My code looks like this, but it has been a while since I've needed to use i2c
     I2CDevice.Configuration c = new I2CDevice.Configuration(0x53, 400);
     Byte[] POWER_CTL = new Byte[] {0x2D, 0x08};
     I2CDevice a = new I2CDevice(c);
     a.Execute(new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(POWER_CTL) }, 100);

#4 walid14


    New Member

  • Members
  • Pip
  • 3 posts

Posted 15 December 2014 - 02:07 PM

@zoot: I am using 5V from the netduino for the Va and I am shorting it to the Vref. I am not too sure if that is how it will work but I just tried that.

I wanted my output to be 3v so I did cross multiplication. 0xFFF represents 5v and x represents 3V. if you convert FFF to integer it is 2047. From there I multiply by 4 and divide by 5 to solve for x and then x is 1228 or 0x4CC. No the byte registervalues is not used anywhere else it was just repeat code.


@spiked: yes i found some code on a site showing a netduino communicating with an arduino and it had similar code but had a loop. I just took what i need from the code. it is not suppose to loop just send one piece of data once to change the output voltage. Well i looked at the data sheet of the chip i am using and it is telling me that the data needs to be stored at a certain slave address given the configuration of the chip. My adr1 and adr0 pins are left floating so the slave address will be 0001100 and that is 0x0C which is byte addr. 

for the code you wrote. What does the address 0x53 represent? and for your new Byte[] what does the 0x2d and 0x88 represent? i will try the kick start just to see if it works.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.