Skip to main content
Engineering LibreTexts

MCP3008 Raspberry Pi Interfacing

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

      The MCP3008 integrated circuit (IC) chip is an analog to digital converter.




      The three areas that must be addressed to collect data with the MCP3008 are, hardware and software and interfacing.


      The section on “Enabling SPI Interface of Raspberry Pi” was found in the following link;

      sudo raspi-config

      The command above will bring up the configuration tool.

      Next go to the interfacing options.



      Enable the SPI.



      Hardware requirements are to have the MCP3008 wired per the method show in the link;

      Connection Between Raspberry Pi and MCP3008

      WARNING: do not attempt to wire up any devices while the RPi is running.

      Place the MCP3008 on the breadboard and wire it up before connecting the ribbon cable to the RPi. Only after rechecking the wiring boot up RPi.


      Software requirements can be satisfied using the following pip command;

      sudo pip3 install adafruit-circuitpython-mcp3xxx

      The documentation can be found here;

      Run the command above to satisfy the software requirements.


      Python example for the MCP3008 found here;

      MCP3008 Single Ended:

      import busio
      import digitalio
      import board
      import adafruit_mcp3xxx.mcp3008 as MCP
      from adafruit_mcp3xxx.analog_in import AnalogIn
      # create the spi bus
      spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
      # create the cs (chip select)
      cs = digitalio.DigitalInOut(board.D5)
      # create the mcp object
      mcp = MCP.MCP3008(spi, cs)
      # create an analog input channel on pin 0
      chan = AnalogIn(mcp, MCP.P0)
      print('Raw ADC Value: ', chan.value)
      print('ADC Voltage: ' + str(chan.voltage) + 'V')

      The following link demonstrates one method for connecting a photoresistor to the RPi through the MCP3008.

      The following fritzing diagram was found in the above link.






      MCP3008 Raspberry Pi Interfacing is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

      • Was this article helpful?