Skip to content

MCP3008‐ADC

John O'Sullivan edited this page Jan 9, 2026 · 8 revisions

MCP3008

2.7V 4-Channel/8-Channel 10-Bit A/D Converters with SPI Serial Interface

Features

  • 10-bit resolution
  • ± 1 LSB max DNL
  • ± 1 LSB max INL
  • 4 (MCP3004) or 8 (MCP3008) input channels
  • Analog inputs programmable as single-ended or pseudo-differential pairs
  • On-chip sample and hold
  • SPI serial interface (modes 0,0 and 1,1)
  • Single supply operation: 2.7V - 5.5V
  • 200 ksps max. sampling rate at VDD = 5V
  • 75 ksps max. sampling rate at VDD = 2.7V
  • Low power CMOS technology
  • 5 nA typical standby current, 2 µA max.
  • 500 µA max. active current at 5V
  • Industrial temp range: -40°C to +85°C
  • Available in PDIP, SOIC and TSSOP packages
image

Wiring for ESP32-S3

  • MCP3008 VDD -> 3.3V (red)
  • MCP3008 VREF -> 3.3V (red)
  • MCP3008 AGND -> GND (black)
  • MCP3008 CLK -> SCLK (yellow)
  • MCP3008 DOUT -> MISO (purple)
  • MCP3008 DIN -> MOSI (white)
  • MCP3008 CS -> #22 (green)
  • MCP3008 DGND -> GND (black)
SPI Bus ESP32 Connection GPIO
SPI SCLK (SCL) SPI clock - MCP3008 CLK GPIO12
SPI MOSI (SDA) Master-out, slave-in MCP3008 DIN -> MOSI GPIO11
SPI MISO (SDO) Master-in, slave-out MCP3008 DOUT -> MISO GPIO13
SPI CS (CS) Chip select MCP3008 CS GPIO17
#include <SPI.h>

// Your wiring
static const int PIN_SCK  = 12;
static const int PIN_MOSI = 11;
static const int PIN_MISO = 13;
static const int PIN_CS   = 17;

// MCP3008 settings
static const uint32_t SPI_HZ = 1000000; // 1 MHz

static uint16_t mcp3008_read_channel(uint8_t channel) {
  if (channel > 7) return 0;

  uint8_t tx1 = 0x01;
  uint8_t tx2 = (uint8_t)(0x80 | (channel << 4));
  uint8_t tx3 = 0x00;

  SPI.beginTransaction(SPISettings(SPI_HZ, MSBFIRST, SPI_MODE0));
  digitalWrite(PIN_CS, LOW);

  uint8_t rx1 = SPI.transfer(tx1);
  uint8_t rx2 = SPI.transfer(tx2);
  uint8_t rx3 = SPI.transfer(tx3);

  digitalWrite(PIN_CS, HIGH);
  SPI.endTransaction();

  (void)rx1;

  uint16_t value = ((rx2 & 0x03) << 8) | rx3;
  return value;
}

void setup() {
  Serial.begin(115200);
  delay(200);

  pinMode(PIN_CS, OUTPUT);
  digitalWrite(PIN_CS, HIGH);

  // Explicitly bind SPI to your chosen pins
  SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI, PIN_CS);

  Serial.println("MCP3008 SPI test starting...");
}

void loop() {
  for (uint8_t ch = 0; ch < 8; ch++) {
    uint16_t v = mcp3008_read_channel(ch);
    Serial.print("CH");
    Serial.print(ch);
    Serial.print("=");
    Serial.print(v);
    if (ch < 7) Serial.print("  ");
  }
  Serial.println();
  delay(500);
}

References

Clone this wiki locally