0

AM2315 i2c and IOError: [Errno 121] Remote I/O error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AM2315 i2c and IOError: [Errno 121] Remote I/O error

by sadfiesch on Mon Apr 19, 2021 9:28 am

Hey All

So i'm currently trying to get the AM2315 to work with the raspberry pi 4 B and I am starting to go crazy I tried everything and read everything avalible about the am2315 and am2320.
I'm using the Am2320 lib and it says it should also work with the am2315.
I attached the sensor to 3.3v sda -> sda and scl -> scl and ground to ground so it is not a hardware issue.
The Sensor works fine I tested it with my arduino no issues there.

pip3 list:
Code: Select all | TOGGLE FULL SIZE
root@cnc:/home/pi# pip3 list
Package                          Version
-------------------------------- ---------
Adafruit-Blinka                  6.4.2
Adafruit-CharLCD                 1.1.1
adafruit-circuitpython-am2320    1.2.6
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-dht       3.6.0
adafruit-circuitpython-hcsr04    0.4.6
adafruit-circuitpython-lis3dh    5.1.9
adafruit-circuitpython-seesaw    1.7.2
adafruit-circuitpython-sgp30     2.3.4
Adafruit-GPIO                    1.0.3
Adafruit-MCP3008                 1.0.2
Adafruit-PlatformDetect          3.5.0
Adafruit-PureIO                  1.1.8
asn1crypto                       0.24.0
certifi                          2018.8.24
chardet                          3.0.4
colorzero                        1.1
cryptography                     2.6.1
entrypoints                      0.3
gpiozero                         1.5.1
idna                             2.6
keyring                          17.1.1
keyrings.alt                     3.1.1
pip                              18.1
pycrypto                         2.6.1
pyftdi                           0.52.9
PyGObject                        3.30.4
pyserial                         3.5
python-apt                       1.8.4.3
pyusb                            1.1.1
pyxdg                            0.25
quick2wire-api                   0.0.0.2
requests                         2.21.0
rpi-ws281x                       4.2.6
RPi.GPIO                         0.7.0
SecretStorage                    2.3.1
setuptools                       40.8.0
Simple-AM2315                    1.0.3
six                              1.12.0
spidev                           3.5
ssh-import-id                    5.7
sysv-ipc                         1.1.0
urllib3                          1.24.1
wheel                            0.32.3
root@cnc:/home/pi#


i2cdetect -y 1 -> I have to execute this 2 times becuase the sensor is asleep the first time.
Code: Select all | TOGGLE FULL SIZE
root@cnc:/home/pi# 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@cnc:/home/pi# 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: -- -- -- -- -- -- -- -- -- -- -- -- 5c -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@cnc:/home/pi#


Code I'm running it is from the simpletest in the am2315 lib:
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import busio
import adafruit_am2320

# create the I2C shared bus
i2c = busio.I2C(board.SCL, board.SDA)
am = adafruit_am2320.AM2320(i2c)

while True:
    print("Temperature: ", am.temperature)
    time.sleep(2)
    print("Humidity: ", am.relative_humidity)
    time.sleep(2)


and the error I'm getting:

Code: Select all | TOGGLE FULL SIZE
root@cnc:/home/pi# python3 am2315.py
Traceback (most recent call last):
  File "am2315.py", line 8, in <module>
    print('Temperature: {0}C'.format(sensor.temperature))
  File "/root/.local/lib/python3.7/site-packages/adafruit_am2320.py", line 112, in temperature
    temperature = struct.unpack(">H", self._read_register(AM2320_REG_TEMP_H, 2))[0]
  File "/root/.local/lib/python3.7/site-packages/adafruit_am2320.py", line 94, in _read_register
    i2c.write(bytes(cmd))
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 84, 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
root@cnc:/home/pi#


I read that the AM2315 is not working to well with the Raspy but it should be able to get at least a reading from it...
Would be happy for any tips.

sadfiesch
 
Posts: 2
Joined: Fri Jan 17, 2020 9:03 am

Re: AM2315 i2c and IOError: [Errno 121] Remote I/O error

by mikeysklar on Tue Apr 20, 2021 2:09 pm

@sadfiesch,

Good job describing your situation (lib versions, code, and output). You have set everything up correctly and the issue is with this sensor AM2315 / AM2320 non-standard i2c wakeup sequence. I don't know an exact way around it, but like you discovered with i2cdetect needing to be run twice the same type of issue is happening the simpletest example code. The sensor is not waking up during i2c initialization and failing to return temperature humidity.

https://github.com/pasko-zh/brzo_i2c/issues/33

I think the best solution is to add some 'try' logic inside your While loop just like we do with the DHT11.

Code: Select all | TOGGLE FULL SIZE
while True:
    try:
        temperature = dht.temperature
        humidity = dht.humidity
        # Print what we got to the REPL
        print("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity))
    except RuntimeError as e:
        # Reading doesn't always work! Just print error and we'll try again
        print("Reading from DHT failure: ", e.args)
 
    time.sleep(1)

mikeysklar
 
Posts: 5798
Joined: Mon Aug 01, 2016 8:10 pm

Re: AM2315 i2c and IOError: [Errno 121] Remote I/O error

by sadfiesch on Wed Apr 21, 2021 6:57 am

This is just sad the sensor is advertised as a I2C sensor but its not exactly following the i2c wake-up sequence standard.
It also seems like this was a know issue for quite a while and when I bought the sensor there was nothing mentioned about this.

I would expect that this should be shown when someone is trying to buy the sensor to save them a lot of wasted time and money. Otherwise this is a total ripoff

For anyone else that is thinkin gabout buying this sensor for the Raspberry PI:
Dont buy it it will not work and you will go crazy trying to get it to work.

sadfiesch
 
Posts: 2
Joined: Fri Jan 17, 2020 9:03 am

Please be positive and constructive with your questions and comments.