Hi ,
I'm using the hideakitai arduino library for MCP4728 DAC microchip and controlling the different outgoing voltages with this library. I don't understand the code of the library so well, but I've managed to make it work. Is there anyone who can help me adjust the code so I can use an Arduino Mega's capability to control two of these chips (because it has two SDA and SCL ports) separately? Right now it's working with the Mega but both chips are getting the same reading, so instead of 8 channels I have double of each of the four channels. Hope that makes sense! GitHub - hideakitai/MCP4728: Arduino library for MCP4728 quad channel, 12-bit voltage output Digital-to-Analog Convertor with non-volatile memory and I2C compatible Serial Interface <- library
my code (that for now just sends a voltage to one channel):
#include <Wire.h>
#include "MCP4728.h"
MCP4728 dac;
int minutes = 60;
int analogPin = A1;
void setup()
{
Serial.begin(115200); // initialize serial interface for print()
Wire.begin();
dac.attatch(Wire, 14);
dac.readRegisters();
dac.selectVref(MCP4728::VREF::VDD, MCP4728::VREF::VDD, MCP4728::VREF::INTERNAL_2_8V, MCP4728::VREF::INTERNAL_2_8V);
dac.selectPowerDown(MCP4728::PWR_DOWN::GND_100KOHM, MCP4728::PWR_DOWN::GND_100KOHM, MCP4728::PWR_DOWN::GND_500KOHM, MCP4728::PWR_DOWN::GND_500KOHM);
dac.selectGain(MCP4728::GAIN::X1, MCP4728::GAIN::X1, MCP4728::GAIN::X2, MCP4728::GAIN::X2);
dac.analogWrite(MCP4728::DAC_CH::A, 0);
dac.analogWrite(MCP4728::DAC_CH::B, 0);
dac.analogWrite(MCP4728::DAC_CH::C, 0);
dac.analogWrite(MCP4728::DAC_CH::D, 0);
dac.enable(true);
dac.readRegisters();
delay(5000);
dac.analogWrite(MCP4728::DAC_CH::B, 3500);
delay(10000);
}
int cur = 3500;
void loop()
{
dac.analogWrite(MCP4728::DAC_CH::B,(cur));
int measurements = 100;
float average = 0.0;
while (measurements > 0){
float value = analogRead(A1)* 0.0049 / 0.2;
average += value;
delay(100);
measurements --;
}
Serial.println(average / 100.0);
}