Multiple MCP3008

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
britracer
 
Posts: 2
Joined: Wed Jun 17, 2020 1:48 pm

Multiple MCP3008

Post by britracer »

I am trying to use 2 x MCP 3008 chips simultaneously using 2 spi interfaces
I have the 2 CS pins connects to CE0 and CE1 on the GPIO (pins 7 and 8)

here is the section of the code setting up the ADC inputs

Code: Select all

import os
import time
import sys
import busio
import board
import digitalio
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

#create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

#create the cs (chip select)
cs0 = digitalio.DigitalInOut(board.D8)
cs1 = digitalio.DigitalInOut(board.D7)

#Address for first MCP3008
mcp0 = MCP.MCP3008(spi, cs0)

#Address for second MCP3008
mcp1 = MCP.MCP3008(spi, cs1)

# create an analog input channel on pin 0
chan1 = AnalogIn(mcp0, MCP.P0)
chan2 = AnalogIn(mcp0, MCP.P1)
chan3 = AnalogIn(mcp0, MCP.P2)
chan4 = AnalogIn(mcp0, MCP.P3)
chan5 = AnalogIn(mcp0, MCP.P4)
chan6 = AnalogIn(mcp0, MCP.P5)
chan7 = AnalogIn(mcp0, MCP.P6)
chan8 = AnalogIn(mcp0, MCP.P7)
chan9 = AnalogIn(mcp1, MCP.P0)
chan10 = AnalogIn(mcp1, MCP.P1)
chan11 = AnalogIn(mcp1, MCP.P2)
chan12 = AnalogIn(mcp1, MCP.P3)
chan13 = AnalogIn(mcp1, MCP.P4)
chan14 = AnalogIn(mcp1, MCP.P5)
chan15 = AnalogIn(mcp1, MCP.P6)
chan16 = AnalogIn(mcp1, MCP.P7)
I can only get the first chip to work. Is there something I am missing?
Last edited by adafruit_support_carter on Wed Jun 17, 2020 5:58 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit_support_carter
 
Posts: 29483
Joined: Tue Nov 29, 2016 2:45 pm

Re: Multiple MCP3008

Post by adafruit_support_carter »

Try swapping the CS pins to something other than CE0/CE1. Even though those are the notional CS pins for the hardware SPI port, the CircuitPython libraries expect the CS pin to just be a normal digital pin. So there may be some pin conflict going on between your program and the OS's use of those pins.

User avatar
britracer
 
Posts: 2
Joined: Wed Jun 17, 2020 1:48 pm

Re: Multiple MCP3008

Post by britracer »

Thanks for the reply. Unfortunately the ADC hat I am using has pins 7 and 8 hardwired as ce0 and ce1

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”