目前,我正试图让两个MCP3008通过SPI与我的raspberry pi和Python脚本进行通信。电位计应向MCP3008输入通道发送一定的模拟值
以下是我在Fritzing中的设置:
以下是示意图概述:
SPI接线基于标准daisychain示意图,如所示:
我使用的Python代码是:
import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 1000000
def read_spi(channel):
spidata = spi.xfer2([0,(8+channel)<<4,0])
return ((spidata[1] & 3) << 8) + spidata[2]
try:
while True:
channeldata = read_spi(0)
print (channeldata)
time.sleep(.1)
except KeyboardInterrupt:
spi.close()
我得到了一些值,但它们波动很大,每一个值都可能在0到1023之间
我用一个没有daisychaining的MCP3008试过,当然,它工作得很好,所以我猜它与daisychain不正确或者MCP3008的寻址有关
你们能帮帮我吗?非常感谢
干杯
德瓦图
目前没有回答
相关问题 更多 >
编程相关推荐