简体   繁体   中英

Why is this code not working for mcp3008? (from official adafruit site)

I'd like some help to debug the example code provided by adafruit. I have connected a potentiometer and an analog servo motor which when using the python2 script give me values just fine. I took from this site: https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008

Since I have to upgrade to python3 I looked into new tutorials here:https://learn.adafruit.com/mcp3008-spi-adc/python-circuitpython

The problem I have is no matter what pin value I give in the board I always get 0 values. The pin I use for mcp3008 selector is BCM 22:

I've also provided an image of the connection here:

mcp3008 potentiometer raspberry pi zero w

import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
cs = digitalio.DigitalInOut(board.D5)
mcp = MCP.MCP3008(spi, cs)

What am I doing wrong? Thanks a lot for your time.

It turns out the raspberry pi required restart which surprised me as I suspect it's because I installed the adafruit packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM