0

I can't get the mcp3008 to work. I have the wiring as in the pictures (hardware wiring), and I've re-checked it a few times, can't find any mistakes there. The left side of the mcp3008 on the picture is the one with the indent. The red wires connect to 3.3v, the left 2 blue ones to gnd. Then:

  • blue connects to BCM 11 SPI0 SCLK
  • green connects to BCM 9 SPI0 MISO
  • yellow connects to BCM 10 SPI0 MOSI
  • orange connects to BCM 8 SPI0 CE0

The red and orange wires on the right side of the breadboard connect to the red and brown wire on the raspi-image (3.3v and gnd respectively). The white wire connect channel 0 to 3.3v.

Pins on breadboard Pins on raspi

I'm running a simple program from Adafruit to test my setup. See the following code:

# License: Public Domain
import time

# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

# 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)

When I run it, it runs fine, but the output is consistently only zeroes on all channels. When I use the white wire to run 3.3v to the green wire (MISO), I get 1023 on all channels. So it seems to be working up to some extent, but I can't get it to do anything useful. What am I doing wrong?

Rien Heuver
  • 275
  • 2
  • 10

1 Answers1

2

The wiring appears to be wrong. The MCP3008 SCLK appears to be connected to ground.

I haven't looked any further.

MCP3008 8 ch 10-bit ADC

CH0     1 o o 16 V+
CH1     2 o o 15 Vref
CH2     3 o o 14 AGND
CH3     4 o o 13 SCLK
CH4     5 o o 12 SDO 
CH5     6 o o 11 SDI 
CH6     7 o o 10 CS/SHDN
CH7     8 o o  9 DGND

1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17
SB SD D2 D1 D0 NA NA B9 B8 B7 B6 B5 B4 B3 B2 B1 B0

SB 1

SD 0=differential 1=single

D2 D1 D0 0-7 channel
joan
  • 71,014
  • 5
  • 73
  • 106
  • Here I am, thinking I wouldn't make such a simple mistake. For future reference and any others stumbling upon this problem: the guide by Adafruit nicely lists the pins and what to connect them to, but they changed up the order for unknown reasons, completely throwing me off... https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008 – Rien Heuver Dec 11 '17 at 21:30