Search code examples
arduinoi2c

I2C - MCP4725 DAC (12bit)


i have alternative signal , want to reconstruction ADC signal with DAC and see result.

i'm not Write DAC value to MCP4725 for reconstruction ADC signal .

how to done it ?

please help me for solve it thank's


Solution

  • From http://henrysbench.capnfatz.com/henrys-bench/arduino-output-devices/arduino-mcp4725-digital-to-analog-converter-tutorial/

    #include <Wire.h>
    #include <Adafruit_MCP4725.h>
    #define voltsIn A0
    
    Adafruit_MCP4725 dac; // constructor
    
    void setup(void) {
      Serial.begin(9600);
      dac.begin(0x60); // The I2C Address: Run the I2C Scanner if you're not sure  
    
    }
    
    void loop(void) {
    
        uint32_t dac_value;
        int adcValueRead = 0;
        float voltageRead = 0;
    
        float dac_expected_output;
    
    
        for (dac_value = 0; dac_value < 4096; dac_value = dac_value + 15)
        {
          dac_expected_output = (5.0/4096.0) * dac_value;
          dac.setVoltage(dac_value, false);
          delay(250);
          adcValueRead = analogRead(voltsIn);
          voltageRead = (adcValueRead * 5.0 )/ 1024.0;
    
          Serial.print("DAC Value: ");
          Serial.print(dac_value);
    
          Serial.print("\tExpected Voltage: ");
          Serial.print(dac_expected_output,3);
    
          Serial.print("\tArduino ADC Value: ");
          Serial.print(adcValueRead);
    
          Serial.print("\tArduino Voltage: ");      
          Serial.println(voltageRead,3);      
        }    
    }