Mcp4725

From Federal Burro of Information
Revision as of 03:10, 5 December 2024 by David (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

got this for the mozzi project.

step one get it to work.

refrence page: https://forum.arduino.cc/t/mcp4725-dac-read-analog-voltage-value-with-arduino-uno/1211524

test script:


#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
// Set this value to 9, 8, 7, 6 or 5 to adjust the resolution
#define DAC_RESOLUTION    (9)

const int pinoAnalogo = A1;

void setup(void) {
  Serial.begin(9600);
  // MCP4725A1 address is 0x62 (default) 
  // MCP4725A1 address is 0x63 (ADDR pin tied to VCC) 
  // MCP4725A1 address is 0x60 (ADDR pin tied to GND) 
  dac.begin(0x60); //I have my ADDR pin connected to GND so address is 0x60
}

void loop(void) {      
  int valorAnalogico = analogRead(pinoAnalogo);
  dac.setVoltage((1*4095)/5, false);        //Set voltage to 1V
  Serial.println(valorAnalogico);
  delay(2000);
  dac.setVoltage((2*4095)/5, false);        //Set voltage to 2V
  Serial.println(valorAnalogico);
  delay(2000);
  dac.setVoltage((3*4095)/5, false);        //Set voltage to 3V
  Serial.println(valorAnalogico);
  delay(2000);
  dac.setVoltage((4*4095)/5, false);        //Set voltage to 4V
  Serial.println(valorAnalogico);
  delay(2000);
  dac.setVoltage(4095, false);              //Set voltage to 5V or (Vcc)
  Serial.println(valorAnalogico);
  delay(2000); 
}