So I am attempting to use an MCP3008 chip to create a Voltage meter with the Raspberry Pi (I have a Pi 2 Model B). I have been following this tutorial:
https://www.raspberrypi.org/learning/physical-computing-with-python/analogue/
Now I am also using a Breakout Board to do these tests, so I had to make a few changes to the wiring because I don't see the same SPI plug ins on the break-out board as are in the tutorial. As such I changed the wiring to those described here:
Measure Voltage with Raspberry Pi? Using a MCP3008?
From my understanding of the tutorial (first link) after I connect the potentiometer, while I have the program running I should be able to turn it and have the displayed value of my voltage go between 0.0 and 1.0. However all I am getting at results of 1.0 even when I turn the potentiometer dial as far in each direction as I can.
Does anyone know what my problem could be? Do I need to do different wiring? I can provide all the pins the Breakout Board has if you'd like. Thanks for the help :)
EDIT: I switched the code I am using to the code Adafruit has on their Github
# Simple example of reading the MCP3008 analog input channels and printing
# them all out.
# Author: Tony DiCola
# License: Public Domain
import time
# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
# Software SPI configuration:
CLK = 18
MISO = 23
MOSI = 24
CS = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Hardware SPI configuration:
# SPI_PORT = 0
# SPI_DEVICE = 0
# mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
print('Reading MCP3008 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)
# Main program loop.
while True:
# Read all the ADC channel values in a list.
values = [0]*8
for i in range(8):
# The read_adc function will get the value of the specified channel (0-7).
values[i] = mcp.read_adc(i)
# Print the ADC values.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
# Pause for half a second.
time.sleep(0.5)
With this code, I see 1023 as the reading for each of the 8 pins. When I rotate the potentiometer, nothing happens. Hell I even removed all the wries from the Breakout board, completely disconnecting the MCP3008 and I was still getting 1023 readings :\
Update to the photo. Wiring has been fixed up a bit, however it is still not working
I have to Pins connected as follows to the labelled Pins o nthe Breakout Board:
Pin 9 (VDD) -> 3V3
Pin 10 (VREF) -> 3V3
Pin 11 (AGND) -> GND
Pin 12 (CLK) -> SCLK
Pin 13 (DOUT) -> MISO
Pin 14 (DIN) -> MOSI
Pin 15 (CS) -> CE0
Pin 16 (DGND) -> GND
EDIT 2: The potentiometer I am using is a B50K which has a power rating of 0.125W