Leon Anavi
IT Tips && Tricks

Mobile & Embedded

Created: 20.06.2021 23:27 Last Modified: 21.06.2021 19:24 Views: 385
Keywords: ADC, analog to digital converter, MCP3002, Microchip, potentiometer, python, Raspberry Pi, Raspberry Pi OS, SPI

Using Analog to Digital Converter (ADC) Microchip MCP3002 on Raspberry Pi Single-board Computer

Raspberry Pi is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in cooperation with Broadcom. Unlike the recently released microcontroller Raspberry Pi Pico, all versions and models of the Raspberry Pi single-board computers do not include an analog-to-digital converter (ADC). This tutorial explains how to use Microchip MCP3002 with Raspberry Pi.

Microchip MCP3002

Microchip MCP3002 is a 10-bit resolution dual channel ADC with SPI hardware interface for connecting to embedded devices such as Raspberry Pi. MCP3002 operates over a broad voltage range, from 2.7V to 5.5V. It is offered in 8-pin MSOP, PDIP, TSSOP and 150 mil SOIC packages. MCP3002 PDIP package is appropriate for prototyping on a breadboard.

Raspberry Pi and Microchip MCP3002 Wiring

Microchip MCP3002 has to be connected to the dedicated SPI pins (MISO, MOSI, SCL and SS) on the Raspberry Pi header. For this tutorial a 10K potentiometer is connected to one of the two channels of the ADC. Both the potentiometer and MCP3002 are powered with 5V from the Raspberry Pi header.

Raspberry Pi Analog to Digital Conveter ADC Microchip MCP3002

Enable SPI

Boot Raspberry Pi OS, the official Debian based GNU Linux distribution by the Raspberry Pi, from a microSD card. Open a terminal and using the raspi-config tool enable SPI as shown in the video. Reboot the Raspberry Pi.

Python Script

Python3 script for reading data from analog devices through MCP3002 is available at the rpi-examples repository in GitHub. The script relies on popular Python package RPi.GPIO. Open a terminal and run the following commands to clone rpi-example and run the script:

git clone https://github.com/leon-anavi/rpi-examples.git
cd rpi-examples/MCP3002/python
python3 adc.py

The potentiometer is an analog device that acts like a variable resistor. Rotate it and observe the output of the Python script for the change of the voltage.

Next Level

PCBWay prototype for a Raspberry Pi add-on board with Microchip MCP3002 ADC

Thanks to PCBway, the sponsor of this video, we can go to the next level and use a prototype of ANAVI Gardening uHAT as a Raspberry Pi add-on board with SOIC package of Microchip MCP3002.

PCBWay prototype for a Raspberry Pi add-on board with Microchip MCP3002 ADC

  Home | About | Contact | Disclaimer | Sitemap 2009-2018 Leon Anavi. All rights reserved.