Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: [Errno 121] Remote I/O error #1

Open
derkod opened this issue Aug 18, 2021 · 11 comments
Open

OSError: [Errno 121] Remote I/O error #1

derkod opened this issue Aug 18, 2021 · 11 comments

Comments

@derkod
Copy link

derkod commented Aug 18, 2021

I'm using your script, but get this error. Googling results in more similar experiences. But as far as I can see, no solution.
Strange thing is that I get an DEVICE_SERIAL which in my opinion means that i2c is correct.
Running with sudo gives same error.

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                
$ ./read_sps30.py 
ARTICLE CODE: 
DEVICE SERIAL: 897DFB40EABF4589
AUTO-CLEANING INTERVAL: 604800
Traceback (most recent call last):
  File "./read_sps30.py", line 31, in <module>
    while not sps.read_data_ready_flag():
  File "/home/pi/.local/lib/python3.7/site-packages/sps30/sps30.py", line 176, in read_data_ready_flag
    self.bus.i2c_rdwr(write)
  File "/home/pi/.local/lib/python3.7/site-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 121] Remote I/O error
@oylern
Copy link

oylern commented Aug 29, 2021

I'm seeing the same thing. If I run the binary directly, I get this:

root@raspberrypi:/home/pi# run-sps30
ARTICLE CODE: 
DEVICE SERIAL: F266FC8A03EE9AD1
AUTO-CLEANING INTERVAL: 0
Traceback (most recent call last):
  File "/usr/local/bin/run-sps30", line 29, in <module>
    while not sps.read_data_ready_flag():
  File "/usr/local/lib/python3.7/dist-packages/sps30/sps30.py", line 176, in read_data_ready_flag
    self.bus.i2c_rdwr(write)
  File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 121] Remote I/O error

...and if I run the sample python script, I get this:

root@raspberrypi:/home/pi# python3 ./sps30.py 
Traceback (most recent call last):
  File "./sps30.py", line 1, in <module>
    from sps30 import SPS30
  File "/home/pi/sps30.py", line 1, in <module>
    from sps30 import SPS30
ImportError: cannot import name 'SPS30' from 'sps30' (/home/pi/sps30.py)

Used pip3 for install per the instructions. Other pertinent info:

os-release:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

I'm using an older model pi I had sitting around, model B v2.0.

@spike322
Copy link

spike322 commented Sep 3, 2021

I'm using your script, but get this error. Googling results in more similar experiences. But as far as I can see, no solution.
Strange thing is that I get an DEVICE_SERIAL which in my opinion means that i2c is correct.
Running with sudo gives same error.

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                
$ ./read_sps30.py 
ARTICLE CODE: 
DEVICE SERIAL: 897DFB40EABF4589
AUTO-CLEANING INTERVAL: 604800
Traceback (most recent call last):
  File "./read_sps30.py", line 31, in <module>
    while not sps.read_data_ready_flag():
  File "/home/pi/.local/lib/python3.7/site-packages/sps30/sps30.py", line 176, in read_data_ready_flag
    self.bus.i2c_rdwr(write)
  File "/home/pi/.local/lib/python3.7/site-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 121] Remote I/O error

I'm having the exact same error. Did you manage to solve it?

@oylern
Copy link

oylern commented Sep 3, 2021

My research shows that i2cdetect may not actually be the definitive proof that i2c is working--even if the ID does come up in the grid. The [Errno 121] Remote I/O error is a generic error (not specific to this library) stating that the i2c bus was not able to communicate with the sensor.

I nearly gave up and sent the sensor back, but opted instead to try UART mode (using the TX/RX pins). That worked super easily using this library: https://avaldebe.github.io/PyPMS/

@feyzikesim
Copy link
Owner

Hey guys,

Sorry for late response. I have been gone for my military service. Remote I/O errors mostly related to poor I2C busses. Did any of you try to use pull-up resistors ?

@oylern
Copy link

oylern commented Sep 6, 2021

No worries! I did use pull-up resistors, but sadly I was not successful in gettin I2C to work. UART mode works great, though, so I just went that route. I did not try different power supply or usb cable but I've read sometimes that weak power or cheap cables can also contribute to similar issues.

@spike322
Copy link

I know for sure that the I2C communication is working because with this code everything works fine https://github.com/brannow/sps30.

But for my project I need a python library to make the sensor work, so it seems there's a problem with this library itself.

@Gretel5X
Copy link

I am running into the same issue when running run-sps30 from a docker-container. Interestingly, it reads Serial Number correctly and always fails on line 20:

DEVICE SERIAL: 69BF79586FAB919F
Traceback (most recent call last):
  File "/usr/local/bin/run-sps30", line 20, in <module>
    sps.device_reset() # device has to be powered-down or reset to check new auto-cleaning interval

If start a Python Console and play around, it only fails here, everything else works just fine:

>>> sps.read_auto_cleaning_interval()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/sps30/sps30.py", line 129, in read_auto_cleaning_interval
    self.bus.i2c_rdwr(read)

It does look like a code issue, maybe not in the sps30 library but in smbus2?

@feyzikesim
Copy link
Owner

feyzikesim commented Oct 15, 2021

@Gretel5X Issue may be related to Python version (and all other pip packages that depends on the Python version). Can you try with 3.5 or 3.6 instead of 3.9 or something else. I'm working from home and don't have the hardware at the moment.

Edit: Also you can try with 0.3.0 version of smbus2.

@Gretel5X
Copy link

Tried 3.6, 3.7 and 3.9 each with smbus2==0.3.0, it will always get stuck at line 20..

Python 3.5 reached EOL last year, 3.6 will reach it this year so I would not really want to use it anyways

@feyzikesim
Copy link
Owner

I remembered that one of the contributor of this project, Felix Belair, sent me an e-mail in June, mentioned that he is struggled with the same problem as you guys. He was able to fix the problem by adding these lines;

def __enter__(self):
    return self

def __exit__(self, exc_type, exc_val, exc_tb):
    self.bus.close()

to SPS30 class and using the driver like this;

with SPS30(1) as sps:
    sps.read_measured_values()

He also said that 1 second rest after each measurement is helpful to prevent crashes.

Please let me know if that works for you too so I can update the driver.

@Gretel5X
Copy link

Gretel5X commented Oct 20, 2021

I tried it and I have not gotten any error messages, even without the context manager. Interestingly, my docker container which is running since a few days and got restarted a couple of times (setting auto-cleaning intervall, reading serial etc) did not log any errors like it used to when I started developing the script. Maybe something in the underlying modules changed?

Using the context manager is not necessary and should not make a difference anyway, only if you have other parts of the code accessing the i2c bus and you want to close the bus after reading the sps30.

It would make sense to add the enter and exit functions anyway to have defined behavior when someone wants to use the context manager.

Edit:
I used python 3.7 and python 3.9.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants