# Connect MCP4821 DAC to Adafruit ESP32

**URL:** <https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712>\
**Category:** Adafruit\
**Created:** [28 June 2019 02:42 UTC](https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712 "2019-06-28T02:42:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerard47075](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@Gerard47075](https://forum.core-electronics.com.au/u/Gerard47075)\
**Post date:** [28 June 2019 02:42 UTC](https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712/1 "2019-06-28T02:42:10Z")

</div>

I have reason to connect a Microchip MCP4821 DAC to my Adafruit HUZZAH32. However, it is not obvious to me where i should connect the CS, SCK and SDI pins of the DAC to the ESP32 board.  
Can anybody advise the correct connections and possible provide sample Arduino source if available.

> **[Adafruit HUZZAH32 – ESP32 Feather Board](https://core-electronics.com.au/adafruit-huzzah32-esp32-feather-board.html)**
>
> Aww yeah, it's the Feather you have been waiting for! The HUZZAH32 is Adafruit's ESP32-based Feather, made with the official WROOM32 module. Adafruit packed everything you love .. read more

  
[https://www.microchip.com/wwwproducts/en/MCP4821#additional-features](https://www.microchip.com/wwwproducts/en/MCP4821#additional-features)  
PS. I’m aware that the ESP32 has 2 DAC’s built in. However, i’m wanting to implement an ADC calibration process from a known and accurate source.

---

<div class="post-metadata">

**Author:** ![Robin57159](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Robin57159](https://forum.core-electronics.com.au/u/Robin57159)\
**Post date:** [28 June 2019 03:48 UTC](https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712/2 "2019-06-28T03:48:12Z")

</div>

On the Huzzah,  
CS - chip select, any available digital pin  
SCK - clock, pin is marked SCK  
MO - (MOSI) master out slave in, to SDI on the MCP.

The SPI pins are up near the antenna on the Huzzah.

---

<div class="post-metadata">

**Author:** ![Gerard47075](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@Gerard47075](https://forum.core-electronics.com.au/u/Gerard47075)\
**Post date:** [30 June 2019 22:21 UTC](https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712/3 "2019-06-30T22:21:17Z")

</div>

Thanks! I see the MO and MI pins now.

---

<div class="post-metadata">

**Author:** ![Gerard47075](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@Gerard47075](https://forum.core-electronics.com.au/u/Gerard47075)\
**Post date:** [5 July 2019 07:01 UTC](https://forum.core-electronics.com.au/t/connect-mcp4821-dac-to-adafruit-esp32/5712/4 "2019-07-05T07:01:35Z")

</div>

We have set up our first test and it will not work as yet. We are getting no output from the MCP4821. We have carefully connected as follows:

> **[22244B.pdf](https://ww1.microchip.com/downloads/en/DeviceDoc/22244B.pdf)**
>
> 1256.92 KB

  
MCP4821 = HUZZAH32  
Vdd = 5Vdc  
CS = A8 (pin 15 on HUZZAH32, is operating correctly)  
SCK = SCK  
SDI = MO  
Vss = GND  
SHDN = NC  
LDAC = GND

Are we using the correct SPI library?  
Is the SPI being initialized properly?  
We do not have an oscilloscope so we cannot look at SCK or MO.  
Does SCK have to be configured\>  
Is there anything obvious in the code below?

```auto
...
#include <SPI.h>
...
void setup() {
  pinMode(A8, OUTPUT);  
  digitalWrite(A8, HIGH);
  SPI.begin();
}

void loop() {
  delay(1000);
  digitalWrite(A8,LOW);
  SPI.transfer(0x3800); //0011100000000000 should output 1.024V (2.048ref, Gain=1,Active)
  digitalWrite(A8,HIGH);
}

```

Thanks heaps for any assistance.  
Regards, Gerard Hook
