Notes on: MCP3008 8 channel Analog to Digital Converter - RichardChambers/raspberrypi GitHub Wiki

Notes on: MCP3008 8 channel Analog to Digital Converter

The MCP3008 ADC (Analog to Digital Converter) is an Integrated Circuit which measures the voltage level of a signal, an analog signal, and provides a digital numeric value that provides a digital representation of the analog signal. The actual digital value will depend on the operating mode of the MCP3008, Single Ended mode or Pseudo-Differential mode.

The MCP3008 talks to the Raspberry Pi over the SPI (Serial Peripherial Interface). The hardware SPI requires certain pins on the the Raspberry Pi to be connected to certain pins on the MCP3008. There is also a software SPI that can be used.

The interface pins of the MCP3008 connected to the Raspberry Pi are:

  • DIN (Data In) which is the serial data input pin for data sent by the Pi to the ADC
  • DOUT (Data Out) which is the serial data output pin for data read by the Pi from the ADC
  • CLK (Clock) which is the clock used to synchronize the DIN and DOUT serial bit signals
  • CS/SHDN (Chip Select/Shutdown) which is used to start and stop a converation

The MCP3008 has two operating modes: Single Ended mode or Pseudo-Differential mode. Single Ended mode provides a digital value that compares the input analog voltage on the channel to the analog reference voltage. Pseudo-Differential mode allows the analog voltage on two channels to be compared (for details as to how Pseudo-Differential mode works, see the MCP3008 data sheet).

In Single Ended mode the MCP3008 samples the channel voltage level and generates a digital value between 0 and 1023, a 10 bit value, to represent the relative level of the channel voltage level compared to the Analog Reference Voltage. The way that the MCP3008 converts the analog signal to a digital signal is by measuring the voltage of the analog signal being sampled and comparing the voltage level to the analog reference voltage. The basic mathematics is something along the lines of SV / RV * 1023 = DV where SV is the Signal Voltage, RV is the Reference Voltage and DV is the Digital Value.

The Analog Reference Voltage must be the maximum voltage that the Analog Signal Voltage may attain.

An application that is using the MCP3008 sends and receives a series of bytes. The bytes the application sends are commands indicating which channel to sample and the response contains the 10 bit digital value representing the voltage level on the channel, Single Ended mode, or the difference between two channels, Pseudo-Differential mode.

Pin out and pin connection diagram

diagram of MCP3008 and Raspberry Pi connection diagram

Further reading

For background on the SPI hardware see the following:

Wikipedia topic Serial Peripheral Interface Bus https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

Sparkfun article Serial Peripheral Interface https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi