AtlasScientific/Raspberry-Pi-sample-code

OSError: [Errno 121] Remote I/O error

farcouet opened this issue · 4 comments

Hello,
I have the ORP and PH sensors since few years without issue. I read the sensors from RexyGen automation program that I made and have no issue. I have stopped the program (to ensure it was not communicating while I want to use Atlas Scientific software to calibrate the probes).
I installed the latest version from Git (I re-imaged my PI as the SD Card died). I am always getting error when trying to use the i2c.py with python 2 or 3. It used to worked before and I know I can communicate with the sensors as my automation has no issue. So there is really something not working and I would expect this to work. I tried to use and older version from Git and still had issue.

Here are the errors. As you can see we can see the PH and ORP at 62 and 63.

root@raspPool:/Raspberry-Pi-sample-code-latest# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- 1b -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- 62 63 -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
root@raspPool:
/Raspberry-Pi-sample-code-latest# python3 i2c.py
Traceback (most recent call last):
File "i2c.py", line 146, in
main()
File "i2c.py", line 59, in main
device_list = get_devices()
File "i2c.py", line 28, in get_devices
response = device.query("I")
File "/root/Raspberry-Pi-sample-code-latest/AtlasI2C.py", line 163, in query
self.write(command)
File "/root/Raspberry-Pi-sample-code-latest/AtlasI2C.py", line 84, in write
self.file_write.write(cmd.encode('latin-1'))
OSError: [Errno 121] Remote I/O error

Same here.
On my Pi 1 B+ my EC and PH sensors works out of the box.
On my Pi 4 i get the exact same message but i2cdetect shows the sensors.

Hello,
This is due to the code probing all the i2c devices and that does not accept some
ack provided by them (example I had other i2c devices). What I did to solve it is edited the script to provide the list of i2c addresses corresponding to the atlas scientific and then commenting the function to scan for deices.
The interesting part is that I had the same issue two weeks ago and spent some time figuring out again!
Cheers,
Fred

Those are the lines to modify.
device_list = get_devices()

device = device_list[0]

I also have this problem with Pi4 but not Pi3. Here's a quick and dirty workaround example.

def get_devices():
    device = AtlasI2C()

    """ 
    2022-10-29 Ductsoup
    Workaround for Raspberry Pi 4
    https://github.com/AtlasScientific/Raspberry-Pi-sample-code/issues/9
    """
    #device_address_list = device.list_i2c_devices()
    device_address_list = []
    device_address_list.append(99)                  # pH
    device_address_list.append(100)                 # EC
    device_address_list.append(102)                 # RTD
   
    device_list = []
    
    for i in device_address_list:
        device.set_i2c_address(i)
        response = device.query("I")
        try:
            moduletype = response.split(",")[1] 
            response = device.query("name,?").split(",")[1]
        except IndexError:
            print(">> WARNING: device at I2C address " + str(i) + " has not been identified as an EZO device, and will not be queried") 
            continue
        device_list.append(AtlasI2C(address = i, moduletype = moduletype, name = response))
    return device_list