I'm currently trying to read values from a pH-probe via an ADS1115 connected to my Raspberry Pi 4. Using the instructions on https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/python-circuitpython I got it to run with this simple code (not by me)
import time, board, busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
i2c = busio.I2C(board.SCL, board.SDA) # Create the I2C bus
ads = ADS.ADS1015(i2c) # Create the ADC object using the I2C bus
chan = AnalogIn(ads, ADS.P0) # Create single-ended input on channel 0
print("{:>5}{:>5}".format('raw', 'v'))
while True:
print("{:>5}{:>5.3f}".format(chan.value, chan.voltage))
time.sleep(0.1)
However, if I change the time.sleep()
to anything greater than 2s I get an [Errno 121] Remote I/O error
.
Traceback (most recent call last):
File "simpletestadc.py", line 22, in <module>
print("{:>5}{:>5.3f}".format(chan.value, chan.voltage))
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/analog_in.py", line 64, in value
self._pin_setting, is_differential=self.is_differential
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/ads1x15.py", line 144, in read
return self._read(pin)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/ads1x15.py", line 172, in _read
self._write_register(_ADS1X15_POINTER_CONFIG, config)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/ads1x15.py", line 205, in _write_register
i2c.write(self.buf)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 102, in write
self.i2c.writeto(self.device_address, buf, start=start, end=end)
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 115, in writeto
return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error
This seems very counterintuitive to me, especially since a simple print(i2c.scan())
inside the loop seems to prevent crashing (output being [72] btw) though now speed is going down drastically.
In my project I'm not interested in getting values every tenth of a second but instead getting ten values in very quick succession every 1 minute or so.
Every question I have seen so far seems to in one way or another indicate a faulty connection between ADC and board, but I'm confident it's not that in my case.
BTW: sudo i2cdetect -y 1
yields an established connection at 0x48 at all times.
By now I'm so confused and in doubt what's wrong. Also, please be aware this is my first serious attempt at RaspberryPi.
I would appreciate any help.
Thank you!
question from:
https://stackoverflow.com/questions/65643602/raspi-i-o-error-121-with-using-ads1115-for-long-time-sleep