2

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

  • Can you please provide an image of your specific physical layout? Editing your question with your code may shed some light on the problem as well. – stevieb Jun 21 '17 at 13:45
  • Best to say what rating of Potentiometer you're using, too. – recantha Jun 21 '17 at 14:10
  • @stevieb Just editted to add the code and a picture of the wiring :) – Skitzafreak Jun 21 '17 at 14:20
  • 1
    It looks like your wiring is wrong. This should match the breakout board (not necessarily the names but the locations) pinout.xyz. You also should use red for VCC and blue for ground on the ground rails - you have the reverse. – Steve Robillard Jun 21 '17 at 14:39
  • 1
    On the Pi the specific pins are setup for SPI communication, you can't just change them at random. – Steve Robillard Jun 21 '17 at 14:59
1

Your wiing looks right now.

Try this code:

from gpiozero import MCP3008
from time import sleep 
pot = MCP3008(0)

while True:
    print(pot.value)
    sleep(1)
  • Thanks. So I think my problem might actually be the Breakout Board. I noticed the ADC seemed to be heating up when I had it plugged in so I ran the beard board's lines through a volt tester and it turns out the 5V & GND were the reverse of what was labelled (with the GND actually carrying the voltage) and on the 3.3V end I'm only getting about 1.79V through. Might I have to get a new Breakout Board? – Skitzafreak Jun 21 '17 at 15:47
  • I doubt the board is wrong. On the ribbon cable, there should be a stripe. the end of the cable with the stripe goes towards the sd card end of the Pi. You may well have fried your ADC. Can you post an additional pick showing the ribbon cable connections? – Steve Robillard Jun 21 '17 at 15:53
  • Yeah, sorry mine are a solid color, not a rainbow. So try this, plug the cable into the board and measure the voltage at the 3.3 and ground pins on the breakout board (disconnect or remove the ADC first) if you don't get 3.3 volts and the right polarity reverse the cable and try again. Also, there should be only one way to plug it in at the breakout board because of the matching lug and notch. – Steve Robillard Jun 21 '17 at 16:10
  • 1
    So yeah, I had the ribbon cable in backwards. The way it's set up is so weird. The ribbon cable runs over top of the breakout board, as opposed to away from it. This won't be annoying at all to work with :P – Skitzafreak Jun 21 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.