Ошибка ввода / вывода при использовании Python ADS1115 и Raspberry Pi - PullRequest
0 голосов
/ 27 июня 2019

Я пытаюсь прочитать аналоговый сигнал, используя ADS1115 и Raspberry Pi. Иногда это читает, и некоторое время приводит к ошибке.

Ниже приведен фрагмент кода

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))

Я использовал попытку, за исключением того, чтобы убедиться, что АЦП работает, но иногда это работает, а иногда приводит к следующей ошибке.

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?

...