我正在尝试使用ADS1115和树莓派读取模拟信号。有时会读取,一段时间后会出错。
以下是代码段
response = {}
adc = Adafruit_ADS1x15.ADS1115()
t_trial = time.time()+2
GAIN = 1
while time.time() < t_end:
try:
test=adc.read_adc(0, gain=GAIN,data_rate=860)
test=adc.read_adc(1, gain=GAIN,data_rate=860)
except IOError as err:
response['Error'] = True
response['ErrorMessage'] = "ADC Failed to read"
conn.send(json.dump(response))
L=[]
Lma = []
t_end = time.time() + 5
## Here I start the system(Using a relay) after which read is to be performed and it is to be done if and only if ADC read is possible.
while time.time() < t_end:
L.append(adc.read_adc(0, gain=GAIN,data_rate=860))
Lma.append(adc.read_adc(1, gain=GAIN,data_rate=860))
除了确保ADC正常工作之外,我都尝试过使用该方法,但这有时可行,有时会导致以下错误。
File "XrayFBServer3.2.py", line 98, in threadServer
L.append(adc.read_adc(0, gain=GAIN,data_rate=860))
File "build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py", line 192, in read_adc
return self._read(channel + 0x04, gain, data_rate, ADS1x15_CONFIG_MODE_SINGLE)
File "build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py", line 128, in _read
self._device.writeList(ADS1x15_POINTER_CONFIG, [(config >> 8) & 0xFF, config & 0xFF])
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 129, in writeList
self._bus.write_i2c_block_data(self._address, register, data)
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 294, in write_i2c_block_data
self._device.write(data)
IOError: [Errno 5] Input/output error
我无法降低data_rate。我应该降低I2con Raspberry Pi的波特率吗?