我是Python新手,目前正在我的pi3modb上做一个项目。我使用Adafruit ADC1015来转换模拟信号。然而,即使我有代码来获得一些电压测量值,我也会得到一个错误“AttributeError:'int'object没有属性'readadcsinglended'”。在
为了解释这一点,我尝试运行的python脚本如下:
#!/usr/bin/python
import time, signal, sys
from Adafruit_ADS1x15 import ADS1x15
def signal_handler(signal, frame):
print 'You pressed Ctrl+C!'
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
ADS1015 = 0x00
ADS1115 = 0x01
gain = 4096 # +/- 4.096V
sps = 250 # 250 samples per second
# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
adc = ADS1015(ic=ADS1015)
# Read channel 0 in single-ended mode using the settings above
volts=adc.readADCSingleEnded(0, gain, sps) / 1000
# To read channel 3 in single-ended mode, +/- 1.024V, 860 sps use:
# volts = adc.readADCSingleEnded(3, 1024, 860)
print "%.6f" % (volts)
我们导入的“ADS1x15”文件包含以下与错误相关的代码:
^{pr2}$我相信这将运行SMMOTHY,因为它是与ADC有关的一部分,但我没有设法解决这个问题,即使我尝试了很多。在
找到了。线路
应该是
^{pr2}$相关问题 更多 >
编程相关推荐