Connect 2 DAC's via SPI

Hi there, I'm currently using this(GitHub - MajenkoLibraries/MCPDAC: Library to control the MCP4822 and similar DAC chips) library to do some tests with a MCP4822 and it works great!
Now I would like to connect a second MCP4822 to my project to add 2 extra outputs. Is that possible with this library? I connect it to the same MOSI and CLK. Only the CS of the 2nd MCP is connected to pin 9.
How can I tell my arduino that there is a second DAC connected?

Hi panapro

Assuming you are not using a latch pin on the DACs, so just MOSI, CLK and CS ...

In your program, add this code before setup() to create a second instance of the DAC object:

MCPDACClass secondDAC;

In setup(), call begin() with the pin number of the second CS:


Then, in your program, use secondDAC instead of MCPDAC when you set gain, set voltage, etc.



Thank you Ray!

It seems that it does the job! I don't get errors in my IDE. Tomorrow I will upload it and let you know.


It is working perfect! Thank you very much!