Processing math: 100%
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

MCP3008 Raspberry Pi Interfacing

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

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

     

    clipboard_ec93c1dad432868b524cc6acdd47b625e.png

    https://en.wikipedia.org/wiki/Analog-to-digital_converter

     

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

    Interfacing:

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

    https://electronicshobbyists.com/raspberry-pi-analog-sensing-mcp3008-raspberry-pi-interfacing/

    sudo raspi-config
    

    The command above will bring up the configuration tool.

    Next go to the interfacing options.

     

    clipboard_e77548be130cda01d07510a7695e1fd98.png

    Enable the SPI.

    clipboard_e6c21e0a48ab68f815eecca750980c78d.png

    Hardware:

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

    Connection Between Raspberry Pi and MCP3008

    https://tutorials-raspberrypi.com/mcp3008-read-out-analog-signals-on-the-raspberry-pi/

    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:

    Software requirements can be satisfied using the following pip command;

    sudo pip3 install adafruit-circuitpython-mcp3xxx
    

    The documentation can be found here;

    https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx/

    Run the command above to satisfy the software requirements.

     

    Python example for the MCP3008 found here;

    https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx/#usage-example

    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.

    https://tutorials-raspberrypi.com/photoresistor-brightness-light-sensor-with-raspberry-pi/

    The following fritzing diagram was found in the above link.

     

     

    clipboard_eb5198b36690d7ae4e6171486c818bed7.png

     

     


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

    Support Center

    How can we help?