Bukit Mertajam, Penang

Reading Analog Signal Using MCP3008 On Raspberry Pi

Introduction

Maybe you’re not interested to write 2 different program on 2 different controller platform as shown in I2C Raspberry Pi Arduino – Reading Analog Signal. Another option, you can read the analog signals using MCP3008 (Analog to Digital – SPI) on Raspberry Pi. This tutorial will show you how.

Video

This video shows how to read analog signals using MCP3008 on Raspberry Pi.

Hardware Preparation

Wiring Connection

1. MCP3008

MCP3008 PinsConnections
1 (CH0)Potentiometer analog signal pin
2 (CH1)LM35 analog signal pin
3 (CH2)
4 (CH3)
5 (CH4)
6 (CH5)
7 (CH6)
8 (CH7)
9 (DGND) GND (Maker pHAT)
10 (CS/SHDN) CE0 (Maker pHAT)
11 (DIN)MOSI (Maker pHAT)
12 (DOUT)MISO (Maker pHAT)
13 (CLK)SCLK (Maker pHAT)
14 (AGND) GND (Maker pHAT)
15 (AREF)3.3V (Maker pHAT)
16 (VDD) 3.3V (Maker pHAT)

 

2. Potentiometer

Potentiometer PinsConnections
13.3V (Maker pHAT)
2CH0 (MCP3008)
3GND (Maker pHAT)

 

3. LM35

LM35 PinsConnections
15V (Maker pHAT)
2CH1 (MCP3008)
3GND (Maker pHAT)

Software Preparation

First, you need to enable I2C and SPI module in Raspberry Pi. Then instal MCP3008 library from Adafruit. Write following command on Terminal.

sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus git
git clone https://github.com/adafruit/Adafruit_Python_MCP3008.git
cd Adafruit_Python_MCP3008
sudo python setup.py install

Sample Code

This is the sample code to display calculated data on I2C LCD.

Thank you

References

  1. Adafruit – Raspberry Pi Analog to Digital Converters
  2. How to Display on I2C LCD Using Raspberry Pi

Thanks for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a comment